LAE

Welcome to the LAE community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Discussions

Members

Resources

Events

 View Only
  • 1.  Converting Unix timestamps

    Employee
    Posted 03-03-2010 14:32

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: rpcwong

    Some of my data has the unix timestamp (seconds since standard epoch of 1/1/1970). I want to convert them back to "normal" date and time, but I'm having difficulties.

    From BRAINscript Language help page, i see

    timestamp(epochMs)
    Evaluates to the datetime value represented by number of milliseconds since the epoch, 1970-1-1 00:00:00, in the local timezone.
    epochMs must be long

    When I try running the following codes:

    firstTime_date = timestamp(long(firstTime))
    currenttime = timestamp()
    emit firstTime, firstTime_date, currenttime

    I get the following output:

    1267466695.02 1970-01-15 16:04:26.695000 2010-03-03 14:26:37
    1267466865.05 1970-01-15 16:04:26.865000 2010-03-03 14:26:37
    1267466728.77 1970-01-15 16:04:26.729000 2010-03-03 14:26:37
    1267466865.07 1970-01-15 16:04:26.865000 2010-03-03 14:26:37
    1267466870.99 1970-01-15 16:04:26.871000 2010-03-03 14:26:37

    But when I tried entering the unix timestamp on some online tool such as
    http://www.unixtimestamp.com/index.php

    I do get reasonable Date (Mar 1, 2010 instead of Jan 15, 1970):
    TIME STAMP: 1267466695.02
    DATE: 03 / 01 / 10 @ 12:04:55pm

    Thoughts? Suggestions?


  • 2.  RE: Converting Unix timestamps

    Employee
    Posted 03-04-2010 08:29

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: ejones

    Try multiplying firstTime by 1000 before converting it to a long representing the milliseconds since January 1st, 1970.

    When I made the change I get 2010-03-01 18:04:55.020000 for your 1267466695.02 value. The difference is down to hours. I think this difference has to do with the time zone on my computer, but I'll have to research this.


  • 3.  RE: Converting Unix timestamps

    Employee
    Posted 03-04-2010 09:18

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: rboccuzzi

    That's correct...the Unix timestamp is the number of seconds since the epoch, and our timestamp is the number of milliseconds since the epoch, so you would need to multiply by 1000. This is also why, incidentally, the type needs to be a long.

    Cheers
    Rich


  • 4.  RE: Converting Unix timestamps

    Employee
    Posted 03-04-2010 09:37

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: rpcwong

    Thank you. That does the trick.