-2

I'm trying to get data from a website, and when I tried to get the date of a post (expected: 13/06/2014 11:55), i got:

23377855

Can someone help me to convert this number to a date? Thanks!

Niunzin
  • 45
  • 1
  • 2
  • 10
  • Sure that's an int? Most likely a long – kolossus Jul 02 '14 at 17:39
  • Is that in unix time? What have you tried? Without more information, this post is doomed to be closed and deleted in the next couple minutes. – Kevin Workman Jul 02 '14 at 17:39
  • I really don't know what is this, I just know that site return "13/06/2014 11:55" and my app return "23377855". (URLConnection) – Niunzin Jul 02 '14 at 17:41
  • With no details about that number, we can't help you. If it's a unix timestamp, it's Sep 28/1970, which is probably not correct. If it's a millisecond timestamp, it's even worse 12:29am, Jan 1/1970. – Marc B Jul 02 '14 at 17:42
  • possible duplicate of [Java: epoch date to MM/DD/YYYY](http://stackoverflow.com/questions/22326468/java-epoch-date-to-mm-dd-yyyy) – Basil Bourque Jul 02 '14 at 17:56
  • I don't have any informations about this number =/ I'll try to get it, thanks all for help! – Niunzin Jul 02 '14 at 18:03
  • Fixed, thanks for all. I just multiplied to 60000. – Niunzin Jul 03 '14 at 16:11
  • using SQLite Date Time functions (using DB Browser sqlite) gives me this: 1970-09-28 07:50:55 – MarkT Dec 12 '20 at 00:14

2 Answers2

1

You can use the standard Java Date API:

        long yourNumber = 23377855;
        Date date = new Date(yourNumber);

Or you can use Joda Time library, provides much better overall functionality than Java Date API:

        long yourNumber = 23377855;
        DateTime dt = new DateTime(yourNumber);
syntagma
  • 23,346
  • 16
  • 78
  • 134
0

Java is expecting milliseconds:

java.util.Date time= new java.util.Date((long)urDateNum*1000);

So you must multiply by 1000

Docs say:

Allocates a Date object and initializes it to represent the specified number of milliseconds since the standard base time known as "the epoch", namely January 1, 1970, 00:00:00 GMT.

Note:

The cast to long is very important in this situation. Without it the integer overflows.

Josef E.
  • 2,179
  • 4
  • 15
  • 30