我正在开发selenium网络驱动程序,希望设置当前日期



我试过这样做:

Date date = new Date();
String lastDate = (date.toString().trim());
// display time and date using toString()
System.out.println(date.toString());

但这里的系统日期显示为:

"Wed Apr 13 15:39:50 IST 2016"

我只需要"MM/dd/yyyy"

DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");

//使用Date() 获取系统的当前日期时间

Date date = new Date();
String date1= dateFormat.format(date);  // Now format the date
// Print the Date
System.out.println("Current date and time is " +date1);

详细信息:http://www.alltestingstuff.com/

您需要格式化它:

DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
//get current date time with Date()
Date date = new Date();
// Now format the date
String dateFormatted= dateFormat.format(date);

下面是一个例子:

SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
System.out.println(dateFormat.format(new Date()));

相关内容

最新更新