Java Time Format stringToTime(String format, String sDate)

Here you can find the source of stringToTime(String format, String sDate)

Description

string To Time

License

Open Source License

Declaration

public static Date stringToTime(String format, String sDate) throws Exception 

Method Source Code


//package com.java2s;
import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {

    public static Date stringToTime(String format, String sDate) throws Exception {
        DateFormat df = new SimpleDateFormat(format);
        Date _date = df.parse(sDate);
        if (timeToString(format, _date).equals(sDate)) {
            return _date;
        } else {/*from  w  w  w. j  a  va  2  s  .  c  o m*/
            throw new Exception(sDate + " is error");
        }
    }

    public static String timeToString(String format, Date date) {
        DateFormat df = new SimpleDateFormat(format);
        return df.format(date);
    }
}

Related

  1. stdTimeFormat(Date date)
  2. string2Long(String sourceTime, String dataFormat)
  3. string2long(String sourceTime, String dataFormat)
  4. stringDateTimeFormat(String dt2Format)
  5. stringTimeToLongTime(String time, String format)
  6. time2Date(Integer time, String format)
  7. time2String(Date time, DateFormat dateFormat)
  8. timeFormatDate(Date d)
  9. timeFormatNano(long delta)