Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static String getCurrentTime(long currentTime) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
        Date curDate = new Date(currentTime);
        String currentDate = formatter.format(curDate);
        return currentDate;
    }

    public static String getCurrentTime() {

        SimpleDateFormat simpleDate = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        return simpleDate.format(new Date());
    }

    public static String getCurrentTime(String pattern) {

        SimpleDateFormat simpleDate = new SimpleDateFormat(pattern);
        return simpleDate.format(new Date());
    }
}