QQ网名大全

j**a如何得到年月日。

1、获取当前的时间

date date=new date();//此时date为当前的时间

2、设置时间的格式

date date=new date();//此时date为当前的时间 

system.out.println(date); 

simpledateformat dateformat=new simpledateformat(“yyyy-mm-dd”);//设置当前时间的格式,为年-月-日 

system.out.println(dateformat.format(date)); 

simpledateformat dateformat_min=new simpledateformat(“yyyy-mm-dd hh:mm:ss”);//设置当前时间的格式,为年-月-日 时-分-秒 

system.out.println(dateformat_min.format(date));

扩展资料

j**a 获取当前微秒时间:

package com.ffcs.itm;

public class datasecutils {

public static void main(string[] args) {

system.out.println(system.currenttimemill**()); // 毫秒

system.out.println(getmictime());

system.out.println(system.currenttimemill**()); // 毫秒

system.out.println(getmictime());

}

/**

* @return返回微秒

*/

public static long getmictime() {

long cutime = system.currenttimemill**() * 1000; // 微秒

long nanotime = system.nanotime(); // 纳秒

return cutime + (nanotime - nanotime / ** * **) / 1000;

}

}

佚名
2024-06-04 04:47:50
最佳回答
类似问题(10)