Copyright © https://mongoose-os.com

Mongoose OS Forum

frame

How to change time Unix in MJS?

i try use the function Date(),but MJS does not support.So I'd like to know how you implement the timeUnix conversion?

Comments

  • SergeySergey Dublin, Ireland
  • liuliu china

    @Sergey said:
    Timer.now()

    May be my expression is not clear enough, my question is, how to convert TimeUnix into standard time? example 2017-05-05 15:21

  • SergeySergey Dublin, Ireland

    There are no JS functions currently for time formatting.

  • liuliu china

    thank you ,so I can only write algorithm conversion, right?

  • bravokeylbravokeyl Seoul, South Korea (Nomadist)
    @liu , what do you mean algorithm conversion? Just use UNIX timestamps and add offset time based on your timezone.

    If you are logging the data to the server, I would recommend to just send UNIX timestamps and do all the conversions on the server end.
  • SergeySergey Dublin, Ireland
    We can add a `Timer.fmt()` function or similar, but I am hesitant.
    Not sure that the device side should do pretty-printing.
  • liuliu china
    edited May 2017
    Sergey said:
    We can add a `Timer.fmt()` function or similar, but I am hesitant.
    Not sure that the device side should do pretty-printing.
    I think it is necessary to add. Because TimeUNIX algorithm conversion is very complex, I think 8266 mcu processing takes a long time, I hope to add! thank you
  • liuliu china
    bravokeyl said:
    @liu , what do you mean algorithm conversion? Just use UNIX timestamps and add offset time based on your timezone.

    If you are logging the data to the server, I would recommend to just send UNIX timestamps and do all the conversions on the server end.
    Yes, I hope I can display the standard time format,But the algorithm is very complex, I can only convert the date, but the specific time I can not convert out!
  • I bumped into this page looking for a solution -- here is how I solved it ... for future googlers.

        let now = Timer.now();
        let hour = ( 24 + Math.floor(now % 86400 / 3600  - 6)) % 24;    // 6 for mountain time
        let min = Math.floor(now % 3600 / 60) ;
        let hhmm = hour + min / 100;
    

    ... giving you 13.50 number for 10 minutes to 2 PM in your timezone that a small device can display
    or store in a more readable manner than 1539028200.

Sign In or Register to comment.