Android Date String to Date Convert iso8601ToTimestamp(final String strDate)

Here you can find the source of iso8601ToTimestamp(final String strDate)

Description

iso To Timestamp

Declaration

public static long iso8601ToTimestamp(final String strDate) 

Method Source Code

//package com.java2s;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class Main {
    private static final ThreadLocal<DateFormat> ISO8601Format = new ThreadLocal<DateFormat>() {
        @Override//  ww w  .j  a  v a  2s  .c  o m
        protected DateFormat initialValue() {
            return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.US);
        }
    };

    public static long iso8601ToTimestamp(final String strDate) {
        Date date = iso8601ToJavaDate(strDate);
        if (date == null)
            return 0;
        return (date.getTime() / 1000);
    }

    public static Date iso8601ToJavaDate(final String strDate) {
        try {
            DateFormat formatter = ISO8601Format.get();
            return formatter.parse(strDate);
        } catch (ParseException e) {
            return null;
        }
    }
}

Related

  1. fromStringFR(String dateString)
  2. fromStringUS(String dateString)
  3. getDateFromString(String dateString, String dateFormat)
  4. getDefaultDateTimeString(String date, Locale locale)
  5. getShortDateTimeString(String date, Locale locale)
  6. iso8601ToTimestamp(final String strDate)
  7. parseCalDav(String date)
  8. parseCalDavDue(String date)
  9. parseDBDateTime(String date)