Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

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

public class Main {
    public static String getCurrentDateTimeinMillis() {
        /*
        long millis = System.currentTimeMillis()%1000;
        String millisStr;
        if(millis < 10){
        millisStr = "00" + String.valueOf(millis);
        }else if(millis < 100){
        millisStr = "0" + String.valueOf(millis);
        }else{
        millisStr = String.valueOf(millis);
        }
        String currentDateTimeinMillis = Helper.getCurrentDateTime()
            + "." + millisStr;*/

        DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd HHmmss.SSS");
        Calendar cal = Calendar.getInstance();
        String currentDateTimeinMillis = dateFormat.format(cal.getTime());
        return currentDateTimeinMillis;
    }
}