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 getYmdDateDiff(String ymdDate) {
        String todayYmd = nowDateYymm();
        String diffResult = "";
        try {
            diffResult = String.valueOf(Integer.parseInt(todayYmd) - Integer.parseInt(ymdDate));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return diffResult;
    }

    public static String nowDateYymm() {
        Calendar cal = Calendar.getInstance();
        java.util.Date currentTime = cal.getTime();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
        String ndate = formatter.format(currentTime);
        return ndate;
    }

    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());
    }
}