Java Timestamp Field getDayStartTimestamp()

Here you can find the source of getDayStartTimestamp()

Description

get Day Start Timestamp

License

Apache License

Declaration

public static long getDayStartTimestamp() 

Method Source Code


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

import java.sql.Timestamp;

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

public class Main {
    public static String DATE_FORMAT = "yyyy-MM-dd";
    public static String TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";

    public static long getDayStartTimestamp() {
        Timestamp[] timestamps = getDayStartEnd();
        return Long.valueOf(dateToStamp(timestamps[0] + ""));
    }//  w w  w .j  a va  2  s .  c  om

    public static Timestamp[] getDayStartEnd() {
        Timestamp[] t = new Timestamp[2];
        String day = new SimpleDateFormat(DATE_FORMAT).format(Calendar.getInstance().getTime());
        t[0] = Timestamp.valueOf(day + " 00:00:00");
        t[1] = Timestamp.valueOf(day + " 23:59:59");
        return t;
    }

    public static String dateToStamp(String date) {
        try {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat(TIME_FORMAT);
            Date date1 = simpleDateFormat.parse(date);
            long ts = date1.getTime() / 1000;
            return String.valueOf(ts);
        } catch (Exception e) {

        }
        return String.valueOf(getDateStamp() / 1000);
    }

    public static Timestamp getTime() {
        String day = new SimpleDateFormat(TIME_FORMAT).format(Calendar.getInstance().getTime());
        return Timestamp.valueOf(day);
    }

    public static long getDateStamp() {
        return (long) System.currentTimeMillis() / 1000;
    }
}

Related

  1. getDayEnd(java.sql.Timestamp stamp, int daysLater)
  2. getDayOfMonthBy(Timestamp ts)
  3. getDayOfTime(Timestamp timestamp)
  4. getDayOfWeek(Timestamp timestamp)
  5. getDaysBetween(Timestamp start, Timestamp end)
  6. getDayTime(Timestamp day, Timestamp time)
  7. getDefaultTimestamp()
  8. getDiffDay(Timestamp time1, Timestamp time2)
  9. getDifferenceInHours(Timestamp startDateTime, Timestamp endDateTime)