Here you can find the source of toXMLDateTime(final Date date)
Transform a Date object to a String formatted according to the specification of the <code>dateTime</code> datatype of XML schema.<br> See <a href="http://www.w3.org/TR/xmlschema-2/#dateTime">section 3.2.7 of the XML Specification</a> for details.
Parameter | Description |
---|---|
date | The date as Calendar object to convert to String. |
xs:dateTime
formatted String or null
when date object was null
public static String toXMLDateTime(final Date date)
//package com.java2s; /**//from ww w . j a va 2s. c om * Copyright (C) 2014 The Holodeck B2B Team, Sander Fieten * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; public class Main { /** * Transform a {@link Date} object to a {@link String} formatted according to * the specification of the <code>dateTime</code> datatype of XML schema.<br> * See <a href="http://www.w3.org/TR/xmlschema-2/#dateTime">section 3.2.7 of the XML * Specification</a> for details. * * @param date The date as Calendar object to convert to String. * @return The date as an <code>xs:dateTime</code> formatted String * or <code>null</code> when date object was <code>null</code> */ public static String toXMLDateTime(final Date date) { if (date == null) return null; SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXX"); formatter.setTimeZone(TimeZone.getTimeZone("UTC")); return formatter.format(date); } }