首页 > 代码库 > String和Date 互相转换

String和Date 互相转换

1.String ->Date

  String StrDate = "2012-12-12";

      SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
      Date date = new Date();
      date=sdf.parse(StrDate);

 

2.Date ->String

   String  StrDate = "";

     Date date = new Date();

   SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");

   StrDate= sdf.format(date);

String和Date 互相转换