Android Date String Parse toDate(String sdate)

Here you can find the source of toDate(String sdate)

Description

to Date

Declaration

public static Date toDate(String sdate) 

Method Source Code

//package com.java2s;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;
import java.util.Locale;

public class Main {
    private final static SimpleDateFormat dateFormater = new SimpleDateFormat(
            "yyyy-MM-dd HH:mm:ss", Locale.CHINA);

    public static Date toDate(String sdate) {
        try {//from   ww w . ja v  a 2s .  co  m
            return dateFormater.parse(sdate);
        } catch (ParseException e) {
            try {
                return dateFormater.parse(new Date(toLong(sdate) * 1000L)
                        .toGMTString());
            } catch (ParseException e1) {
                return null;
            }
        }
    }

    public static long toLong(String obj) {
        try {
            return Long.parseLong(obj);
        } catch (Exception e) {
        }
        return 0;
    }
}

Related

  1. parseDateString(String dateStr, String pattern, Locale locale)
  2. parseSimpleDate(String dateString)
  3. parseUTCFormattedDateString(String dateString)
  4. parseYoutubeDate(String rawDate)
  5. stringToDate(String str)
  6. toDate(String sdate)
  7. toDateFormat(String d, String delim)
  8. parseDate(CharSequence input)
  9. parseDate(CharSequence input, Date defaultDate)