get Current Time No Dash - Java java.util

Java examples for java.util:Time

Description

get Current Time No Dash

Demo Code


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

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

    public static String getCurrentTimeNoDash14() {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
        String curDate = formatter.format(Calendar.getInstance().getTime());
        return curDate;
    }

    public static String getCurrentTimeNoDash14(Date dt) {

        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
        String curDate = formatter.format(dt);
        return curDate.substring(0, 14);
    }
}

Related Tutorials