get current Time in String in yyyyMMddHHmmssSSS format - Java java.util

Java examples for java.util:Time Format

Description

get current Time in String in yyyyMMddHHmmssSSS format

Demo Code


//package com.java2s;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class Main {
    public static void main(String[] argv) {
        System.out.println(getTimeStr());
    }/*from w w w  . j a v a2 s.  c om*/

    public static String getTimeStr() {
        DateFormat df = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        Calendar calendar = Calendar.getInstance();
        return df.format(calendar.getTime());

    }
}

Related Tutorials