Java Millisecond Format getTimeInMillis(String dateString, String format)

Here you can find the source of getTimeInMillis(String dateString, String format)

Description

get Time In Millis

License

Apache License

Declaration

public static long getTimeInMillis(String dateString, String format) 

Method Source Code

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

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

public class Main {
    public static long getTimeInMillis(String dateString, String format) {
        long ts = 0L;

        try {//from   w w  w .j a  v a2s.  com
            SimpleDateFormat sdf = new SimpleDateFormat(format);

            Date date = sdf.parse(dateString);
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
            calendar.set(Calendar.HOUR_OF_DAY, 0);
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MILLISECOND, 0);

            ts = calendar.getTimeInMillis();
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return ts;
    }
}

Related

  1. getMillisAsFormattedSeconds(long millis)
  2. getMvoDateFormatForMilliSecond()
  3. getReadableMillis(long startMillis, long endMillis)
  4. getReadableMillisTime(long millis)
  5. getTime(long timeInMillis, SimpleDateFormat dateFormat)
  6. microseconds2milliseconds(double us)
  7. millis2hms(final long t)
  8. millis2samples(long ms, double sampleRate)
  9. millis2seconds(long millis)