The current date and time formatted as ISO 8601. - Java java.util

Java examples for java.util:Date Format

Description

The current date and time formatted as ISO 8601.

Demo Code


//package com.java2s;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
    public static void main(String[] argv) throws Exception {
        System.out.println(dateTimeISO8601());
    }//from  ww  w .  j  a va2  s  . c o m

    /**
     * The current date and time formatted as ISO 8601.
     *
     * @return current date time as ISO 8601
     */
    public static String dateTimeISO8601() {
        DateFormat dateFormat = new SimpleDateFormat(
                "yyyy-MM-dd'T'HH:mm:ss");
        Date date = new Date();

        return dateFormat.format(date);
    }
}

Related Tutorials