user3776241 user3776241 - 15 days ago 5
Java Question

Date to timestamp

I'm trying to convert this date string 2014-07-17T22:41:17+0000 to a timestmap, similar to this: 1405645259000.

I've tried something similar to this:

String string = "January 2, 2010";
Date date = new SimpleDateFormat("MMMM d, yyyy", Locale.ENGLISH).parse(string);

How do I convert this (2014-07-17T22:41:17+000) to a Date? What is the correct format? I'm at a loss.


Take a look at

Your date string has the same format as

yyyy-MM-dd'T'HH:mm:ssZ  //Eg: 2001-07-04T12:08:56-0700

So, your code should be:

String string = "2014-07-17T22:41:17+0000";
Date date = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.ENGLISH).parse(string);