Here you can find the source of parseXsdDateTime(String date)
Parameter | Description |
---|---|
date | the String to format. |
public static Date parseXsdDateTime(String date) throws ParseException
//package com.java2s; import java.text.SimpleDateFormat; import java.text.ParseException; import java.util.Date; public class Main { private static SimpleDateFormat XSD_DATE_TIME_FORMAT = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ssZ"); /**/*from w w w . jav a 2s .c om*/ * Parses a String that is formatted according to the xsd:dateTime data type * and returns it as a Date * @param date the String to format. * @return the parse date. */ public static Date parseXsdDateTime(String date) throws ParseException { // Trim any whitespace (e.g. a newline at the end of the string) String newDate = date.trim(); if (newDate.endsWith("Z")) { // Remove the Z and replace with "+0000" newDate = newDate.substring(0, newDate.length() - 1) + "+0000"; } else { // Remove the last colon from the string (i.e. the time offset) int colonPos = newDate.lastIndexOf(":"); newDate = newDate.substring(0, colonPos) + newDate.substring(colonPos + 1, newDate.length()); } return XSD_DATE_TIME_FORMAT.parse(newDate); } }