获取Date型的当前系统时间,请大家帮忙解答。
第1个回答 推荐于2017-05-21
Calendar c=Calendar.getInstance();
int y=c.get(Calendar.YEAR);
int m=c.get(Calendar.MONTH);
int d=c.get(Calendar.DATE);String date=y+"-"+m+"-"+d; Date d=java.sql.Date.valueOf(time);
int y=c.get(Calendar.YEAR);
int m=c.get(Calendar.MONTH);
int d=c.get(Calendar.DATE);String date=y+"-"+m+"-"+d; Date d=java.sql.Date.valueOf(time);
第2个回答 2013-05-24
//导入
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
Date dt=new Date();//如果不需要格式,可直接用dt,dt就是当前系统时间
DateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");//设置显示格式
String nowTime="";
nowTime= df.format(dt);//用DateFormat的format()方法在dt中获取并以yyyy/MM/dd HH:mm:ss格式显示本回答被网友采纳
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
Date dt=new Date();//如果不需要格式,可直接用dt,dt就是当前系统时间
DateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");//设置显示格式
String nowTime="";
nowTime= df.format(dt);//用DateFormat的format()方法在dt中获取并以yyyy/MM/dd HH:mm:ss格式显示本回答被网友采纳