import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
class DateTime {
public String getDate() {
SimpleDateFormat ft=null;
Date date=null;
Calendar cl= Calendar.getInstance();
cl.setTime(new java.util.Date());
String year = cl.get(Calendar.YEAR);
String month = cl.get(Calendar.MONTH);
String day = cl.get(Calendar.Day);
date=cl.getTime();
//生成的时间格式
ft=new SimpleDateFormat("yyyy-MM-dd HH:mm");
String dateTime = ft.format(date);
return dateTime;
}
public static void main(String[] args)
{
GetDate gd=new GetDate();
String time=gd.getDate();
System.out.println(time);
//得到时间戳
Date date = new Date();
long timestamp = date.getTime()/1000;
}
public String getSimpleDate(){
String date = new SimpleDateFormat("yyyyMMddHHmm").format(new Date());
}
}
java 时间 date
最新推荐文章于 2024-08-14 23:12:09 发布