Java String to Timestamp getTimestampFromDateString(String date)

Here you can find the source of getTimestampFromDateString(String date)

Description

This method computes the timestamp of the beginning of the day (UTC), given a random string yyyy-MM-dd

License

Open Source License

Declaration

public static long getTimestampFromDateString(String date) throws ParseException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    /**/*from   w  w  w. j  a  v  a2  s.c  o  m*/
     * This method computes the timestamp of the beginning of the day (UTC), given a random string yyyy-MM-dd
     **/
    public static long getTimestampFromDateString(String date) throws ParseException {
        Calendar cal = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        cal.setTime(sdf.parse(date));
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        return (cal.getTimeInMillis() / 1000L);
    }
}

Related

  1. getTimestamp(String pattern)
  2. getTimeStamp(String pattern, String strDate)
  3. getTimeStamp(String style, Date date)
  4. getTimestamp(String timeStampStr, String logRundateIdStr)
  5. getTimestamp(String timezone, String dateTime, String pattern)
  6. getTimeStampInSecond(String timeStr)
  7. isTimestamp(String str, boolean allowEmpty)
  8. isTimeStampValid(String timestamp)
  9. string2Timestamp(String dateString, String timezone)