Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.text.DecimalFormat;

import java.util.Calendar;

public class Main {
    /**
     * yyyyMMddHHmmss
     */
    public static String getFormatTime2(long time) {
        Calendar c = Calendar.getInstance();
        c.setTimeInMillis(time);
        String strFileName = getFormatTime3(c);
        return strFileName;
    }

    /**
     * yyyyMMddHHmmss
     */
    public static String getFormatTime3(Calendar c) {
        DecimalFormat df = new DecimalFormat("00");
        String strFileName = c.get(Calendar.YEAR) + df.format((c.get(Calendar.MONTH) + 1))
                + df.format(c.get(Calendar.DAY_OF_MONTH)) + df.format(c.get(Calendar.HOUR_OF_DAY))
                + df.format(c.get(Calendar.MINUTE)) + df.format(c.get(Calendar.SECOND));

        return strFileName;
    }
}