Here you can find the source of stringToDate(String datecontent, String format)
Description:Get the date according to specific String content The default format is "yyyy-MM-dd"
Parameter | Description |
---|---|
String | a parameter |
public static Date stringToDate(String datecontent, String format)
//package com.java2s; /*//from w w w . ja va 2s . c o m * $RCSfile: DatetimeUtil,v $$ * $Revision: 1.0 $ * $Date: 2011 $ * * Copyright (C) 2011 GyTech, Inc. All rights reserved. * * This software is the proprietary information of GyTech, Inc. * Use is subject to license terms. */ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { /** * <p>Description:Get the date according to specific String content * The default format is "yyyy-MM-dd" * </p> * @param String * @return Date */ public static Date stringToDate(String datecontent, String format) { if (format == null || format.equals("")) format = "yyyy-MM-dd"; try { SimpleDateFormat bartDateFormat = new SimpleDateFormat(format); Date date = bartDateFormat.parse(datecontent); return date; } catch (ParseException pe) { @SuppressWarnings("unused") String message = "Exception occurs in Parse progress."; } catch (Exception e) { @SuppressWarnings("unused") String message = "Exception occurs during the string converting to Date."; } return null; } }