Java Hour Format formatAsXsdDateTime(Date date)

Here you can find the source of formatAsXsdDateTime(Date date)

Description

Returns a date formatted according to the xsd:dateTime data type

License

Open Source License

Parameter

Parameter Description
date the date to format.

Return

the formatted date.

Declaration

public static String formatAsXsdDateTime(Date date) 

Method Source Code

//package com.java2s;

import java.text.SimpleDateFormat;

import java.util.Date;
import java.util.TimeZone;

public class Main {
    private static SimpleDateFormat XSD_DATE_TIME_FORMAT = new SimpleDateFormat(
            "yyyy-MM-dd'T'HH:mm:ssZ");

    /**//w  ww  .j  ava2 s  .c o m
     * Returns a date formatted according to the xsd:dateTime data type
     * @param date the date to format.
     * @return the formatted date.
     */
    public static String formatAsXsdDateTime(Date date) {
        // Set time zone on formatter
        XSD_DATE_TIME_FORMAT.setTimeZone(TimeZone.getDefault());
        // Format the date
        StringBuffer buffer = new StringBuffer(
                XSD_DATE_TIME_FORMAT.format(date));
        // Add the colon into the time offset
        buffer.insert(buffer.length() - 2, ':');

        return buffer.toString();
    }
}

Related

  1. formatAllDate(Date date)
  2. formatAsCassandraDateTime(Date date)
  3. formatAsDateAndTime(Date date)
  4. formatAsHour(long l)
  5. formatAsRoundTripDate(Date date)
  6. formatCalendarForXpath(Calendar date)
  7. formatCalTime(Date time)
  8. formatCapDate(Calendar cal)
  9. formatCompleteDate(Date date)