onedrivelive-connect-sdk

HOWTO to parse Skydrive API date in JAVA


The Skydrive API sends dates as a String e.g. 2013-05-28T14:55:32+0000

I searched on the internet (e.g. here), and this type of date doesn't seem to be a standard one.

I tried folowwing code and the parsing throws an exception:

SimpleDateFormat SKYDRIVE_DATEFORMATTER = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z", Locale.ENGLISH);
long time = 0;
try {       
   // Skydrive returns the modification date as string, not as long
   time = SKYDRIVE_DATEFORMATTER.parse(fixedDate).getTime();
} catch (ParseException e) {
   time = 0;
}

Solution

  • I was making a mistake with the date format. Using following line it works now:

    SimpleDateFormat SKYDRIVE_DATEFORMATTER = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.ENGLISH);