java中获取当前时间

您所在的位置:网站首页 time_t转为cstring java中获取当前时间

java中获取当前时间

2023-04-01 13:26| 来源: 网络整理| 查看: 265

long timeTestStart=System.currentTimeMillis();//记录开始时间

long timeTestEnd=System.currentTimeMillis();//记录结束时间

     System.out.println("运行beanshell消耗时间:"+(timeTestEnd-timeTestStart)+"ms(毫秒)");

ystem.currentTimeMillis()产生一个当前的毫秒,这个毫秒其实就是自1970年1月1日0时起的毫秒数,Date()其实就是相当于Date(System.currentTimeMillis());因为Date类还有构造Date(long date),用来计算long秒与1970年1月1日之间的毫秒差。得到了这个毫秒数,我们自己也可以算起现在的年月日周时,但是这不是我们去计算的,因为有Calendar。Calendar最终出的结果就是年月日周时时区。System.currentTimeMillis() 获得的是自1970-1-01 00:00:00.000 到当前时刻的时间距离,类型为longString.valueOf(System.currentTimeMillis()) 这个语句可转为以下的型式:long ct = System.currentTimeMillis();String t = String.valueOf(ct);其实上面的String t就相当于 ct+"";只是转为字符串格式

public String refFormatNowDate() {  Date nowTime = new Date(System.currentTimeMillis());  SimpleDateFormat sdFormatter = new SimpleDateFormat("yyyy-MM-dd");  String retStrFormatNowDate = sdFormatter.format(nowTime);

  return retStrFormatNowDate;}



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3