Tip: Setting Clock from Windows Desktop

Posted on
  • The project I am working on needs the Clock to be set to the current Date/Time. Its a bit of a pain doing this every time the device restarts so I now use the following batch file (setClock.bat) from my desktop (assumes COM5 & instance of Clock called clk):

    @echo off
    
    for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
    set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2%T%ld­t:~8,2%:%ldt:~10,2%:%ldt:~12,6%
    
    echo clk.setClock((new Date("%ldt%")).valueOf())>COM5
    

    (Ensure the IDE isn't connected)

    Don't ask me to explain it in any detail (used some googled code!)

    Maybe there is an easier way?

  • @DaveNI thanks! That's a really neat idea - one of the first uses of echo I've seen so far as well.

    Just to say that in the GitHub version of Espruino (1v71 when it is released) I've stopped it resetting the RTC on power up/reset - so once you've set the Espruino clock it'll keep time (as long as it's powered!) even after a hard reset.

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

Tip: Setting Clock from Windows Desktop

Posted by Avatar for DaveNI @DaveNI

Actions