当前位置:首页 > 后端开发 > JAVA获取当前系统时间System.currentTimeMillis()

JAVA获取当前系统时间System.currentTimeMillis()

6个月前 (05-26)46

System.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 到当前时刻的时间距离,类型为long
String.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;
}

http://blog.sina.com.cn/s/blog_7309444701016yv5.html

作者:天之骄子19
来源链接:https://www.cnblogs.com/tianzijiaozi/p/7639805.html

“JAVA获取当前系统时间System.currentTimeMillis()” 的相关文章

Java 根据当前日期,获取到月初,和月底时间

SimpleDateFormat format = new SimpleDateFormat("yyyy-M...

Java获取当前时间的年月日方法

1 package com.ob; 2 3 import java.text.ParseException; 4 import java.text.SimpleDa...

java比较当前时间与所需时间比较

try{ //规定格式 (格式根据自己数据库取得的数据进行规范) SimpleDateFormat sdf=new SimpleDateForma...

java获取指定倒退或向前的时间工具类

最近,业务中碰见需要获取指定的时间,比如向前倒推一定的时间,向后倒推一定的时间,此次记载一下处理的相关代码逻辑, //获取当前时间向后推一天...

Java获取当前系统时间

Java获取当前系统时间 // 导入 import  java.util.Date; import &n...

java后台获取当前时间

String now = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyy...

JAVA获取当前日期时间所在周的周一和周日日期

/** * 获取当前时间所在周的周一和周日的日期时间 * @return */ public static Map<String,String> getWee...

Java8  LocalDateTime获取当前时间(戳)

Java8 LocalDateTime获取当前时间(戳)

以上都是获取当前时间的时间戳。而要想使用localdateTime获取当前时间,只需要LocalDateTime.now()即可。 结果如下:...

Java 当前时间面板的构建 自动更新时间

Java 当前时间面板的构建 自动更新时间

问题:       众所周知,很多软件会在某一个地方显示当前时间,以方便用户进行操作,今天我贴一段代码实现时间面板的构...

Java 实例

Java 实例

    1 package guyu.day0831; 2 3 import java.text.SimpleDateForma...