[Python] How to create and manipulate JavaScript Date objects from Brython

Discussão em 'Python' iniciado por Stack, Julho 26, 2025.

  1. Stack

    Stack Membro Participativo

    I am using Brython without importing the Python standard library. (If I am cutting a steak with a screwdriver, please let me know.)

    I would like to write Brython code to do the work of routine date manipulation in JavaScript:

    var foo = new Date()
    foo.setHours(4)
    var time = foo.getTime()


    In my searching, I thought I saw that the first line could be approximated in Brython by:

    from javascript import Date
    foo = Date.new()


    However, I ran into trouble trying to call Date.new() (and also new Date() and just Date()) from Brython; the last one returned a string giving the time, without obvious methods of JavaScript Date objects.

    Is there a winning approach using Brython without the Python standard library to handle e.g. routine creation and manipulation of JavaScript Date objects, or should I use Brython with the standard library and use Python's datetime facilities?

    Thanks,

    Continue reading...

Compartilhe esta Página