Java Date XML Format formatXMLDate(Date date, String pattern)

Here you can find the source of formatXMLDate(Date date, String pattern)

Description

format XML Date

License

Apache License

Declaration

public static String formatXMLDate(Date date, String pattern) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.*;

import java.text.*;

public class Main {
    public static String formatXMLDate(Date date) {
        StringBuffer sb = new StringBuffer();
        addXMLHeader(sb);//from  ww w  .  j a v a  2 s . com
        sb.append("<Date>");
        sb.append(Long.toString(date.getTime()));
        sb.append("</Date>");
        return (sb.toString());
    }

    public static String formatXMLDate(Date date, String pattern) {
        StringBuffer sb = new StringBuffer();
        addXMLHeader(sb);
        sb.append("<Date pattern=\"");
        sb.append(pattern);
        sb.append("\" >");
        SimpleDateFormat fmt = new SimpleDateFormat(pattern);
        sb.append(fmt.format(date));
        sb.append("</Date>");
        return (sb.toString());
    }

    public static void addXMLHeader(StringBuffer sb) {
        sb.append("<?xml version=\"1.0\"?>\n");
    }
}

Related

  1. formatDateToXML(Date dateTime)
  2. formatToXMLDate(Date date)
  3. formatXml(Date date)
  4. getTime(String xmlDateTime)
  5. getXmlTime(Date date)
  6. parse(String xmlDateTime)
  7. toXMLDateTime(final Date date)