Time on Puck.js correct but not date

Posted on
  • I've having a weird issue on Puck with datetime.

    I have "Send time to Espruino" set in the IDE.

    If I do new Date(Date.now()).getHours() or new Date(Date.now()).getMinutes(), I get the right thing.

    But new Date(Date.now()).getMonth() is returning 5 and new Date(Date.now()).getDay() is also returning 5. (That's for today). Yesterday it was 4 for getDay().

    This is on 1v92 using standalone Windows IDE espruino_ide_win64_0v65.9

    Any idea where this offset could be coming from?

  • Odd - what happens if you do (new Date()).toString()

  • Hmm, it's right:

    "Fri Jun 9 2017 10:36:48 GMT+0000"

  • Strange. Maybe it's the way you do new Date(Date.now()) rather than just new Date() - I guess it could also be a bracketing thing.

    Also, the values returned for getMonth/etc start from 0 - not 1. So you'd expect this month - the 6th month - to return 5. The fact the days are wrong is very strange though

  • Good to know re month, thanks.

    Ahhhhhhhhhhhh, getDay() is Day of Week!

    User error completely :-) Ignore me ;-)

  • No problem - glad it's sorted ;)

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

Time on Puck.js correct but not date

Posted by Avatar for ConorONeill @ConorONeill