0

If I save the source html from a Direct Message page in Twitter, I find something like this, which seems to include a detailed timestamp:

<span class="_timestamp" data-aria-label-part="last" data-time="1469168058" data-long-form="true" data-include-sec="true">Jul 22</span>

If i read this data (in Java for example, including only java.io.*) is there a way that I can convert the number in data-time="1469168058" to date and time with hours and minutes, and maybe seconds?

believer
  • 13
  • 4
  • And also a duplicate of [this](http://stackoverflow.com/q/8262333/642706) and [this](http://stackoverflow.com/q/11871120/642706) and many more. Please search Stack Overflow before posting. – Basil Bourque Jul 23 '16 at 23:02
  • Please @Basil read my question more carefully. I did not ask how to convert "seconds from epoch" in Java. I began with Twitter and html scan. If that is the same as seconds from Java epoch, fine. Just tell me. I did search and was not able to find references to "data-time". Sorry. – believer Jul 24 '16 at 00:46
  • As such this is not a duplicate question - for two reasons. First, as I said above, this was a Twitter question. Second, the "duplicate" answers are not exactly right - Twitter adjusts the seconds value for my local time. The conversion is correct for local time *if* I do not set a time zone. – believer Jul 24 '16 at 00:52
  • I do thank @Basil for pointing me in the direction of time display examples. It saved me some "time" (pun) in coding my solution. :) – believer Jul 24 '16 at 00:58

1 Answers1

0

Unix/Posix time

A count around one and a half million usually means a count of whole seconds since the first moment of 1970 in UTC. This is commonly known as Unix time or Posix time.

java.time

In Java a moment on the timeline in UTC with a resolution of nanosecond is represented by the Instant class.

long input = 1_469_168_058L;
Instant instant = Instant.ofEpochSecond ( input );

To see that same moment through the lens of a specific time zone, apply a ZoneId to produce a ZonedDateTime object.

ZoneId zoneId = ZoneId.of ( "America/Chicago" );
ZonedDateTime zdt = instant.atZone ( zoneId );

Dump to console.

System.out.println ( "input: " + input + " | instant: " + instant + " | zdt: " + zdt );

input: 1469168058 | instant: 2016-07-22T06:14:18Z | zdt: 2016-07-22T01:14:18-05:00[America/Chicago]

This result matches the July 22 also included in your data block.

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154