String和Date 互相转换

Posted 厚积薄发

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 互相转换的主要内容,如果未能解决你的问题,请参考以下文章