Here you can find the source of stringToDate(final String string, final String format)
Parameter | Description |
---|---|
string | a parameter |
format | a parameter |
public static Date stringToDate(final String string, final String format)
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; public class Main { public static final String YEAR_MONTH_DAY_HOUR_MINUTE_SECOND = "yyyy-MM-dd HH:mm:ss"; /**//from w ww. j ava2 s. c o m * parse the string to date format:yyyy-MM-dd HH:mm:ss * * @param string * @return Date */ public static Date stringToDate(final String string) { return stringToDate(string, YEAR_MONTH_DAY_HOUR_MINUTE_SECOND); } /** * parse the string to date * * @param string * @param format * @return Date */ public static Date stringToDate(final String string, final String format) { return stringToDate(string, format, null); } /** * parse the string to date * * @param string * @param format * @param locale * @return Date */ public static Date stringToDate(final String string, final String format, final Locale locale) { Date date = null; SimpleDateFormat sdf = new SimpleDateFormat(format, locale == null ? Locale.getDefault() : locale); try { date = sdf.parse(string); } catch (Exception e) { throw new RuntimeException(e); } return date; } }