Format a date to String as yyyy-MM-dd'T'HH:mm:ss.SSSZ format - Java java.util

Java examples for java.util:Date Format

Description

Format a date to String as yyyy-MM-dd'T'HH:mm:ss.SSSZ format

Demo Code


//package com.java2s;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static void main(String[] argv) throws Exception {
        Date dat = new Date();
        System.out.println(formatDate(dat));
    }//  w w w . j  a v  a2s  . co m

    private final static SimpleDateFormat dateFmt = new SimpleDateFormat(
            "yyyy-MM-dd'T'HH:mm:ss.SSSZ");

    /** Format a date as text */
    public static String formatDate(Date dat) {
        return dateFmt.format(dat);
    }
}

Related Tutorials