Java Day dayToUTCSeconds(String day)

Here you can find the source of dayToUTCSeconds(String day)

Description

Convert String of day to epoch time for UTC

License

Open Source License

Parameter

Parameter Description
day a parameter

Exception

Parameter Description
ParseException an exception

Declaration

public static long dayToUTCSeconds(String day) throws ParseException 

Method Source Code


//package com.java2s;

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.TimeZone;

public class Main {
    /**/* w  w  w.j  a  v a2 s  .c  om*/
     * Convert String of day to epoch time for UTC
     * @param day
     * @return
     * @throws ParseException
     */
    public static long dayToUTCSeconds(String day) throws ParseException {
        return dayToSeconds(day, "UTC");
    }

    /**
     * Convert String of day to epoch time for targeted time zone.
     * @param day
     * @param timeZone
     * @return
     * @throws ParseException
     */
    public static long dayToSeconds(String day, String timeZone) throws ParseException {
        return dayToMilliSeconds(day, timeZone) / 1000;
    }

    /**
     * Convert String of day to epoch time for targeted time zone.
     * @param day
     * @param timeZone
     * @return
     * @throws ParseException
     */
    public static long dayToMilliSeconds(String day, String timeZone) throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        simpleDateFormat.setTimeZone(TimeZone.getTimeZone(timeZone));
        return simpleDateFormat.parse(day).getTime();
    }
}

Related

  1. daysFrom(Date date, int amount, String format)
  2. daysOfnumbe(Date sDate, int number)
  3. daySub(Date fDate, Date oDate)
  4. daysWeekName(boolean shortName, Locale locale)
  5. dayToMilliSeconds(String day, String timeZone)
  6. getDateYYMMDD()
  7. getDateYYMMDD(java.util.Date date)
  8. getDay(Date date)
  9. getDay(Date date)