JAVA获取当前系统时间System.currentTimeMillis()
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;
}
JAVA获取当前系统时间System.currentTimeMillis()的更多相关文章
- JAVA获取当前系统时间System.currentTimeMillis()以及获取运行时间
System.currentTimeMillis()产生一个当前的毫秒,这个毫秒其实就是自1970年1月1日0时起的毫秒数,Date()其实就是相当于Date(System.currentTimeMi ...
- Java 获取当前系统时间方法比较
转载: http://blog.csdn.net/zzjjiandan/article/details/8372617 一. 获取当前系统时间和日期并格式化输出: import java.util.D ...
- java 获取当前系统时间
Java的Date获取时间函数都是deprecated 可以使用: https://stackoverflow.com/questions/5175728/how-to-get-the-current ...
- java获取当前系统时间
阿里巴巴推荐 Timestamp d = new Timestamp(System.currentTimeMillis()); 唯一的好处就是除了Timestamp,没有再新建什么了
- java/python中获取当前系统时间,并与字符串相互转换格式,或者转化成秒数,天数等整数
java转换成秒数 Date类有一个getTime()可以换回秒数,例如: public class DateToSecond { public static void main(String[] a ...
- JAVA中获取当前系统时间及格式转换
JAVA中获取当前系统时间 一. 获取当前系统时间和日期并格式化输出: import java.util.Date;import java.text.SimpleDateFormat; publi ...
- JAVA中获取当前系统时间
一. 获取当前系统时间和日期并格式化输出: import java.util.Date;import java.text.SimpleDateFormat; public class NowStrin ...
- 关于Java中获取当前系统时间
一. 获取当前系统时间和日期并格式化输出: import java.util.Date; import java.text.SimpleDateFormat; public class NowStri ...
- java 获取当前系统系时间
//SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式 SimpleDateFo ...
随机推荐
- C++的几种强制类型转换
有时我们希望显式地将对象强制类型转换成另外一种类型.例如,如果想在下面的代码中执行浮点数除法: int i, j; double slope = i / j; 就要使用某种方法将i和/或j显式地转换成 ...
- vilte/vowifi
vendor/mediatek/proprietary/packages/services/Ims/src/com/mediatek/ims/ImsService.java ¦ ¦ ¦ ¦ ¦ ¦ v ...
- 国内下Android源码地址
1 Android 4.4 with kernel: http://pan.baidu.com/s/1bnuDtHt 下载后,请务必阅读 必读.txt 2 android 5.0源码下载 http:/ ...
- POJ 2533 Longest Ordered Subsequence 最长递增序列
Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequenc ...
- ios沙盒路径
http://www.cnblogs.com/ios-wmm/p/3299695.html iOS沙盒路径的查看和使用 NSString *path = NSHomeDirectory();//主目录 ...
- SqlSever基础 datediff 计算人的生日是不准确的,示例
镇场诗:---大梦谁觉,水月中建博客.百千磨难,才知世事无常.---今持佛语,技术无量愿学.愿尽所学,铸一良心博客.------------------------------------------ ...
- socket 异步选择 WSAAsyncSelect 用法
WSAAsyncSelect 实现给异步socket给了另一种实现方式,就是通过窗口消息的方式来提醒对socket接收还是发送 msdn有非常全面的解释:https://msdn.microsoft. ...
- Cheatsheet: 2014 11.01 ~ 11.30
Mobile Android SDK: Working with Picasso View Debugging in Xcode 6 5 Common C# tasks in Apple Swift ...
- Logical Address->Linear Address->Physical Address
3 registers for starting pos: LDTR, GDTR( register for starting addr of DT) ---段描述符每个段由一个8字节(64位)的段描 ...
- iOS开发学习笔记:基础篇
iOS开发需要一台Mac电脑.Xcode以及iOS SDK.因为苹果设备都具有自己封闭的环境,所以iOS程序的开发必须在Mac设备上完成(当然,黑苹果应该也是可以的,但就需要花很多的精力去折腾基础环境 ...