Here you can find the source of toDate(String dateStr)
Parameter | Description |
---|---|
dateStr | a parameter |
public static Date toDate(String dateStr)
//package com.java2s; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; public class Main { /**/*from w ww .j a v a2s . com*/ * This function is use to convert string date format to data format * @param dateStr * @return */ public static Date toDate(String dateStr) { return toDate(dateStr, null); } /** * Convert string date format with time zone * @param dateStr * @param tz * @return */ public static Date toDate(String dateStr, TimeZone tz) { if (tz == null) tz = TimeZone.getDefault(); if (dateStr == null) return null; SimpleDateFormat fmt = null; if (dateStr.length() == 19) { fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); fmt.setTimeZone(tz); } else { fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z"); } try { return fmt.parse(dateStr); } catch (ParseException e) { return null; } } }