获取时间

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

public class NowString {
public static void main(String[] args) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
System.out.println(df.format(new Date()));// new Date()为获取当前系统时间
}
}

 

有时候要把String类型的时间转换为Date类型,通过以下的方式,就可以将你刚得到的时间字符串转换为Date类型了。

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

java.util.Date time=null;
try {
   time= sdf.parse(sdf.format(new Date()));

} catch (ParseException e) {

   e.printStackTrace();
}

 

当前月:int month = c.get(Calendar.MONTH)+1;

posted @ 2017-05-16 20:29  L伟铭  阅读(111)  评论(0编辑  收藏  举报