Java XML Date formatXmlDate(Calendar cal)

Here you can find the source of formatXmlDate(Calendar cal)

Description

Formats a calendar into an XML-formatted date only (without the time).

License

Open Source License

Parameter

Parameter Description
cal The calendar to format.

Return

A String of the date, or "null" if null.

Declaration

public static String formatXmlDate(Calendar cal) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Calendar;

import javax.xml.bind.DatatypeConverter;

public class Main {
    /**//w  w w.  j  ava  2  s. c o m
     * Formats a calendar into an XML-formatted date only (without the time).
     * Example: "2014-02-04"
     * If null, "null" is returned.
     * @param cal The calendar to format.
     * @return A String of the date, or "null" if null.
     */
    public static String formatXmlDate(Calendar cal) {
        if (cal == null) {
            return "null";
        }

        // Get the substring, so that the timezone portion is not included.
        return DatatypeConverter.printDate(cal).substring(0, 10);
    }
}

Related

  1. dateToDouble(Object value)
  2. dateToString(Date date)
  3. dateToString(Date date)
  4. dateToXsdDateTime(Date date)
  5. extractXsdDatetime(String string)
  6. getDateTimeRepresentation(Calendar date)
  7. getDateTimeString(Date dateTime)
  8. getXMLDate(final Date date)
  9. getXSDDateTimeFromCalendar(Calendar calTime)