Here you can find the source of dateToString(Calendar calendar)
Parameter | Description |
---|---|
calendar | the date to be formatted |
public static String dateToString(Calendar calendar)
//package com.java2s; /*// ww w .j a v a 2 s . c om * Copyright 2013 by the digital.me project (http://www.dime-project.eu). * * Licensed under the EUPL, Version 1.1 only (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: * * http://joinup.ec.europa.eu/software/page/eupl/licence-eupl * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is distributed on an "AS IS" basis, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. */ import java.util.Calendar; import java.util.GregorianCalendar; import java.util.TimeZone; import javax.xml.datatype.DatatypeFactory; import javax.xml.datatype.XMLGregorianCalendar; public class Main { private static DatatypeFactory dtFactory; /** * Formats the given date into its string representation * according to the ISO 8601 (e.g. 2003-01-22). * Time zone is ignored. * * @param calendar the date to be formatted * @return formatted date as specified in ISO 8601 */ public static String dateToString(Calendar calendar) { GregorianCalendar utcCalendar = new GregorianCalendar(TimeZone.getTimeZone("UTC")); utcCalendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DATE)); XMLGregorianCalendar xmlCalendar = dtFactory.newXMLGregorianCalendar(utcCalendar); xmlCalendar = xmlCalendar.normalize(); return xmlCalendar.toXMLFormat(); } }