Java XML Date printDateTime(final Date date)

Here you can find the source of printDateTime(final Date date)

Description

Formats a date value in a string, assuming UTC timezone and Canada locale.

License

Open Source License

Parameter

Parameter Description
date The date to format, or null .

Return

The formatted date, or null if the given date was null.

Declaration

public static String printDateTime(final Date date) 

Method Source Code


//package com.java2s;
/*/* w  w  w.j av a 2  s .  c om*/
 *    Geotoolkit.org - An Open Source Java GIS Toolkit
 *    http://www.geotoolkit.org
 *
 *    (C) 2009-2012, Open Source Geospatial Foundation (OSGeo)
 *    (C) 2009-2012, Geomatys
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License as published by the Free Software Foundation;
 *    version 2.1 of the License.
 *
 *    This library 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
 *    Lesser General Public License for more details.
 */

import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.xml.bind.DatatypeConverter;

public class Main {
    /**
     * The Gregorian calendar to use for {@link #printDateTime}.
     *
     * @since 3.06
     */
    private static final ThreadLocal<Calendar> CALENDAR = new ThreadLocal<Calendar>() {
        @Override
        protected Calendar initialValue() {
            return new GregorianCalendar(TimeZone.getTimeZone("UTC"), Locale.CANADA);
        }
    };

    /**
     * Formats a date value in a string, assuming UTC timezone and Canada locale.
     * This method should be used only for occasional formatting.
     *
     * @param  date The date to format, or {@code null}.
     * @return The formatted date, or {@code null} if the given date was null.
     *
     * @see DatatypeConverter#printDateTime(Calendar)
     *
     * @since 3.06
     */
    public static String printDateTime(final Date date) {
        if (date == null) {
            return null;
        }
        final Calendar calendar = CALENDAR.get();
        calendar.setTime(date);
        return DatatypeConverter.printDateTime(calendar);
    }
}

Related

  1. getXSDDateTimeFromCalendar(Calendar calTime)
  2. isPreEIDAS(Date date)
  3. isValidDateUpdatedType(Calendar value)
  4. printDate(final Calendar date)
  5. printDate(java.util.Date dt)
  6. printDateUpdatedType(Calendar value)
  7. string2millis(String lexicalXSDDateTime)
  8. toDate(String date)
  9. toJavaDate(String dateStr)