Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: LGPL 

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

public class Main {

    public static String getTimeMillisToFullDate(long milliSeconds) {
        Calendar cal = Calendar.getInstance();
        java.util.Date currentTime = cal.getTime();
        // Create a DateFormatter object for displaying date in specified format.
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        // String ndate = formatter.format(currentTime);
        // Create a calendar object that will convert the date and time value in milliseconds to date. 
        cal.setTimeInMillis(milliSeconds);
        return formatter.format(cal.getTime());
    }

    public static String getTime() {
        return getCurrentDateTime("yyyy-MM-dd HH:mm:ss");
    }

    public static String getCurrentDateTime() {
        Date today = new Date();
        Locale currentLocale = new Locale("KOREAN", "KOREA");
        // String pattern = "yyyyMMddHHmmss";
        String pattern = "yyyy-MM-dd HH:mm:ss";
        // String pattern = "yyyy-MM-dd";
        SimpleDateFormat formatter = new SimpleDateFormat(pattern, currentLocale);
        return formatter.format(today);
    }

    public static String getCurrentDateTime(String pattern) {
        SimpleDateFormat simpleDateFormat = (pattern == null) ? new SimpleDateFormat()
                : new SimpleDateFormat(pattern);
        return simpleDateFormat.format(new Date());
    }
}