Timestamp, epoc time, and console.log

Posted on
  • After some testing I've realize that epoch time from Date.now() and returned from setWatch() are different, and yes it is documented that 2nd one is using float.

    I wanted to see in human readable format, and i can do for the result of Date.now(), ie:

    console.log("now "+Date.now());
    //1677093816456.81469726562
    var keyDate = new Date(Date.now());    
    console.log("converted Date.now",keyDate);   
    //Wed Feb 22 2023 20:23:36 GMT+0100     OK
    

    But I have problems with console.log when using the float from setWatch()

    setWatch( function(btnx) {
        console.log("time "+btnx.time);
        //1677093816.43038654327
        console.log("time *1000 "+btnx.time*1000);
        //1677093816430.38647460937        
        var pressDate = new Date(btnx.time*1000);
        console.log("pressDate "+pressDate);
        //1677093816430.38647460937    WHY???
      }
      ,BTN1, {repeat:true, edge:'falling'}
    );
    

    On the other hand, from the IDE console, when i assign the previous float*1000 to a var I can see a human readable value, i.e

     var miDate = new Date(1677093816.43038654327*1000);
        //Feb 22 2023 20:23:36 GMT+0100  OK
    
        console.log("miDate "+miDate);
        // 1677093816430.38647460937   WHY????  
    

    I am sure that there is an easy explanation and my issue is causes from the lack of theoretical basics.

  • I am seeing that it is as easy as adding to .toString() to get the format xxx Feb xx 2023 h:mm:ss GMT+0100

    console.log("pressDate "+pressDate.toString());

    for some reason when using the Date.now() the to String was implicit

  • I think it's the difference between these two?

    console.log("converted Date.now"+keyDate);   
    console.log("converted Date.now",keyDate);   
    
  • Yes, you are right

    Not good to read/write code at afternoon, if i read 100 times, I wouldn't see this different character/operator...

    Also i was sure that all console.log were based in copy/paste and using the same operator....

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

Timestamp, epoc time, and console.log

Posted by Avatar for dapgo @dapgo

Actions