Android examples for java.util:Date Format
get Task Due Date From Iso String
/**/*from w w w.j a v a 2 s . c o m*/ * Copyright (c) 2012 Todoroo Inc * * See the file "LICENSE" for the full license governing this code. */ //package com.java2s; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import android.util.Log; public class Main { private static final String ISO_8601_FORMAT = "yyyy-MM-dd'T'HH:mm:ssz"; public static Date getTaskDueDateFromIso8601String(String s) { System.err.println("Importing date string: " + s); Date date = getDateFromIso8601String(s); System.err.println("Got date: " + date); if (date != null) { if (date.getHours() == 23 && date.getMinutes() == 59 && date.getSeconds() == 59) { date.setHours(12); date.setMinutes(0); date.setSeconds(0); } } return date; } /** * Take an ISO 8601 string and return a Date object. * On failure, returns null. */ public static Date getDateFromIso8601String(String s) { SimpleDateFormat df = new SimpleDateFormat(ISO_8601_FORMAT); try { return df.parse(s); } catch (ParseException e) { Log.e("DateUtilities", "Error parsing ISO 8601 date"); return null; } } }