Here you can find the source of toDate(String date, String format)
Parameter | Description |
---|---|
date | a parameter |
format | a parameter |
public static Date toDate(String date, String format)
//package com.java2s; //License from project: Apache License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { /**// www .j a v a 2s. c o m * * @param date * @return */ public static Date toDate(String date) { try { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); if (date.length() == 10) sdf = new SimpleDateFormat("yyyy-MM-dd"); return sdf.parse(date); } catch (ParseException pe) { throw new RuntimeException(pe); } } /** * * @param date * @param format * @return */ public static Date toDate(String date, String format) { try { SimpleDateFormat sdf = new SimpleDateFormat(format); return sdf.parse(date); } catch (ParseException pe) { throw new RuntimeException(pe); } } }