Java Code Examples

To discuss Java SE, Java EE technologies.
正文

How to convert String to Date

(2008-08-25 19:38:22) 下一個
The codes below show you how to convert String to Date in Java.

The copyright of the codes belongs to www.javaeecoding.com

import java.text.DateFormat;
import
java.text.SimpleDateFormat;
import
java.text.ParseException;
import java.util.Date;

public class StringToDateConverter
{
public static void main(String[] args)
{
DateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM-dd");

try

{

// to convert String to Date in format yyyy-MM-dd

Date date1 = dateFormat1.parse("2008-08-09");
System.out.println("date1 = " + date1);
}

catch (ParseException ex)
{
ex.printStackTrace();
}

}
}


[ 打印 ]
閱讀 ()評論 (0)
評論
目前還沒有任何評論
登錄後才可評論.