Java XML Date dateToXsdDateTime(Date date)

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

Description

Converts a Date object to the corresponding XSD DateTime String.

License

Open Source License

Parameter

Parameter Description
date the date to parse

Return

corresponding XSD DateTime

Declaration

public static String dateToXsdDateTime(Date date) 

Method Source Code


//package com.java2s;
/*//  w  w w.j  a v  a 2  s .  co  m
 * $Id: DateUtils.java 327 2014-01-27 13:07:13Z blaser $
 *
 * Copyright (C) 2006-2012 by Bundesamt f?r Justiz, Fachstelle f?r Rechtsinformatik
 *
 * 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 2
 * 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, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

import javax.xml.bind.DatatypeConverter;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class Main {
    /**
     * Converts a Date object to the corresponding XSD DateTime String.
     *
     * @param date the date to parse
     * @return corresponding XSD DateTime
     */
    public static String dateToXsdDateTime(Date date) {
        Calendar calendar = GregorianCalendar.getInstance();
        calendar.setTime(date);
        return DatatypeConverter.printDateTime(calendar);
    }
}

Related

  1. convertDate(String date)
  2. dateToDouble(Object value)
  3. dateToString(Date date)
  4. dateToString(Date date)
  5. extractXsdDatetime(String string)
  6. formatXmlDate(Calendar cal)
  7. getDateTimeRepresentation(Calendar date)
  8. getDateTimeString(Date dateTime)