Convert a Torn Timestamp to YY/MM/DD hh:mm:ss | API Developmen…

Convert a Torn Timestamp to YY/MM/DD hh:mm:ss

    • HOU5E [2337920]
    • Role: Civilian
    • Level: 15
    • Posts: 1,606
    • Karma: 1,209
    • Last Action: 21 minutes
      • 0
    • Reason:
      Are you sure you want to report this post to staff?
      Cancel
    Thread created on 00:14:38 - 03/02/22 (2 years ago)
    |
    Last replied 10:47:33 - 13/02/22 (2 years ago)
    I would like help creating a formula to convert a torn timestamp such as "1643806272" into a human readable date (ie YY/MM/DD hh:mm:ss).

    Thanks

    ANSWER (edit):
    Torn/Unix Timestamps are the number of seconds since Jan 1st 1970.
    Last edited by HOU5E on 22:33:28 - 13/02/22
    • cmahnster [2735178]
    • Role: Civilian
    • Level: 38
    • Posts: 25
    • Karma: 5
    • Last Action: 1 year
      • 0
    • Reason:
      Are you sure you want to report this post to staff?
      Cancel
    Posted on 01:31:21 - 03/02/22 (2 years ago)
    Post link copied to clipboard Copy post link
    I'm having trouble with this too. Is it Unix time? (According to wikipedia, Unix time is the number of seconds since 00:00:00 UTC, January 1, 1970).
    • DeKleineKobini [2114440]
    • Role: Committee
    • Level: 100
    • Posts: 3,745
    • Karma: 5,371
    • Last Action: 4 minutes
      • 0
    • Reason:
      Are you sure you want to report this post to staff?
      Cancel
    Posted on 07:09:23 - 03/02/22 (2 years ago)
    Post link copied to clipboard Copy post link
    It's indeed Unix time. Converting it depends on your language used though.

    Most languages allow you to from unix millis (hence the * 1000, as Torn is in seconds) to their date object:
    • Javascript: "new Date(unix * 1000);"
    • Java Date (old Date object): "new Date(unix * 1000);"
    • Java LocalDateTime (java 8+): check here
    • for other languages I'll leave the research to you

    Once you have that date object, you can then convert it to a readable format:
    • Javascript: you'll probably have to do this yourself (using "getFullYear()", "getMonth() + 1" (january = 0, it's weird, I know), etc...)
    • Java Date (old Date object): "SimpleDateFormat format = new SimpleDateFormat("yy/MM/dd HH:mm:ss"); String result = format.format(date);"
    • Java LocalDateTime (java 8+): "DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yy/MM/dd HH:mm:ss"); String result = date.format(formatter)"
    Last edited by DeKleineKobini on 07:09:31 - 03/02/22
    • LouBaker [1162207]
    • Role: Civilian
    • Level: 100
    • Posts: 3,013
    • Karma: 1,868
    • Last Action: 25 minutes
      • 0
    • Reason:
      Are you sure you want to report this post to staff?
      Cancel
    Posted on 12:02:40 - 10/02/22 (2 years ago)
    Post link copied to clipboard Copy post link
    Visual Basic is pretty easy

    Function UnixToDate(ByVal UnixTime as Long) As Date

    UnixToDate= DateAdd("s", UnixTime, DateSerial(1970, 1, 1))

    End Function
    • HOU5E [2337920]
    • Role: Civilian
    • Level: 15
    • Posts: 1,606
    • Karma: 1,209
    • Last Action: 21 minutes
      • 0
    • Reason:
      Are you sure you want to report this post to staff?
      Cancel
    Posted on 04:57:36 - 11/02/22 (2 years ago)
    Post link copied to clipboard Copy post link
    So in simple terms Torn (Unix) timestamp is the number of seconds since Jan 1st 1970. Ok.
    • Ulung_PL [379891]
    • Role: Civilian
    • Level: 17
    • Posts: 582
    • Karma: 732
    • Last Action: 2 hours
      • 0
    • Reason:
      Are you sure you want to report this post to staff?
      Cancel
    Posted on 22:46:56 - 12/02/22 (2 years ago)
    Post link copied to clipboard Copy post link
    For python

    from time import strftime, gmtime
    strftime('%Y-%m-%d %H:%M:%S', gmtime(1644019200))

    '2022-02-05 00:00:00'
    ..why would anyone but a total loser pay money to play a browser game????
    • Zog [2668287]
    • Role: Civilian
    • Level: 40
    • Posts: 20
    • Karma: 7
    • Last Action: 17 minutes
      • 0
    • Reason:
      Are you sure you want to report this post to staff?
      Cancel
    Posted on 10:47:33 - 13/02/22 (2 years ago)
    Post link copied to clipboard Copy post link
    For php


    $theTime = '1643806272';

    echo(date("Y/M/D h:m:s",$theTime));

    >> 2022/Feb/Wed 12:02:12


    or...


    $theTime = '1643806272';

    echo(date("Y/M/d h:m:s",$theTime));

    >> 2022/Feb/02 12:02:12
Reply
Thread Title: