Java Timestamp Create getTimestamp(final File file)

Here you can find the source of getTimestamp(final File file)

Description

get Timestamp

License

Open Source License

Declaration

public static long getTimestamp(final File file) 

Method Source Code

//package com.java2s;

import java.io.File;

import java.text.DecimalFormat;

import java.util.Calendar;

public class Main {
    public static long getTimestamp(final File file) {
        final long modified = file.lastModified();
        return Long.parseLong(timestamp(modified));
    }//from w  w  w . j  av a  2  s  . c  o  m

    public static String timestamp(final long millis) {
        final Calendar date = Calendar.getInstance();
        date.setTimeInMillis(millis);
        return timestamp(date);
    }

    public static String timestamp(final Calendar date) {
        final DecimalFormat format = new DecimalFormat("00");
        final int month = date.get(Calendar.MONTH) + 1;
        final int day = date.get(Calendar.DAY_OF_MONTH);
        final int hour = date.get(Calendar.HOUR_OF_DAY);
        final int minute = date.get(Calendar.MINUTE);
        final int second = date.get(Calendar.SECOND);
        return "" + date.get(Calendar.YEAR) + format.format(month) + format.format(day) + format.format(hour)
                + format.format(minute) + format.format(second);
    }
}

Related

  1. getTimeStamp(Date date)
  2. getTimeStamp(Date date)
  3. getTimestamp(Date date)
  4. getTimestamp(Date date, String timestampPattern)
  5. getTimestamp(Date time)
  6. getTimestamp(final LocalDate date)
  7. getTimestamp(final Map map, final Object key)
  8. getTimestamp(int offset)
  9. getTimestamp(int year, int month, int day, int hour, int min, int second)