strip fractional seconds from timestamp before parsing

This commit is contained in:
iNPUTmice 2015-02-10 11:11:01 +01:00
parent d1076588f4
commit 6c8b82dd66
2 changed files with 4 additions and 6 deletions

View File

@ -33,7 +33,7 @@ public abstract class AbstractGenerator {
public final String IDENTITY_NAME = "Conversations 1.0";
public final String IDENTITY_TYPE = "phone";
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US);
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
protected XmppConnectionService mXmppConnectionService;

View File

@ -1,5 +1,6 @@
package eu.siacs.conversations.parser;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
@ -40,11 +41,8 @@ public abstract class AbstractParser {
public static Date parseTimestamp(String timestamp) throws ParseException {
timestamp = timestamp.replace("Z", "+0000");
SimpleDateFormat dateFormat;
if (timestamp.contains(".")) {
dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSZ", Locale.US);
} else {
dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ",Locale.US);
}
timestamp = timestamp.substring(0,19)+timestamp.substring(timestamp.length() -5,timestamp.length());
dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ",Locale.US);
return dateFormat.parse(timestamp);
}