Java Date XML Format formatDateToXML(Date dateTime)

Here you can find the source of formatDateToXML(Date dateTime)

Description

format Date To XML

License

Open Source License

Declaration

public static String formatDateToXML(Date dateTime) 

Method Source Code


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

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    private static final String XML_DATE_TIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss";

    public static String formatDateToXML(Date dateTime) {
        return formatDate(dateTime, XML_DATE_TIME_FORMAT);
    }// w w  w .ja v a 2s. c om

    public static String formatDate(Date dateTime, String format) {
        if (dateTime != null) {
            SimpleDateFormat formatter = new SimpleDateFormat(format);
            String result = formatter.format(dateTime);
            return result;
        } else {
            return null;
        }
    }
}

Related

  1. formatToXMLDate(Date date)
  2. formatXml(Date date)
  3. formatXMLDate(Date date, String pattern)
  4. getTime(String xmlDateTime)