java 获取当前系统时间
Java的Date获取时间函数都是deprecated
可以使用:
https://stackoverflow.com/questions/5175728/how-to-get-the-current-date-time-in-java
所说方法
It depends on what form of date / time you want:
If you want the date / time as a single numeric value, then
System.currentTimeMillis()
gives you that, expressed as the number of milliseconds after the UNIX epoch (as a Javalong
). This value is a delta from a UTC time-point, and is independent of the local time-zone ... assuming that the system clock has been set correctly.If you want the date / time in a form that allows you to access the components (year, month, etc) numerically, you could use one of the following:
new Date()
gives you aDate
object initialized with the current date / time. The problem is that theDate
API methods are mostly flawed ... and deprecated.Calendar.getInstance()
gives you aCalendar
object initialized with the current date / time, using the defaultLocale
andTimeZone
. Other overloads allow you to use a specificLocale
and/orTimeZone
. Calendar works ... but the APIs are still cumbersome.new org.joda.time.DateTime()
gives you a Joda-time object initialized with the current date / time, using the default time zone and chronology. There are lots of other Joda alternatives ... too many to describe here.in Java 8, calling
LocalDateTime.now()
andZonedDateTime.now()
will give you representations for the current date / time.
Prior to Java 8, most people who know about these things recommended Joda-time as having (by far) the best Java APIs for doing things involving time point and duration calculations. With Java 8, this is no longer true. However, if you are already using Joda time in your codebase, there is no strong reason to migrate.
date和datetime转换
https://stackoverflow.com/questions/19431234/converting-between-java-time-localdatetime-and-java-util-date
Date in = new Date();
LocalDateTime ldt = LocalDateTime.ofInstant(in.toInstant(), ZoneId.systemDefault());
Date out = Date.from(ldt.atZone(ZoneId.systemDefault()).toInstant());
java 获取当前系统时间的更多相关文章
- Java 获取当前系统时间方法比较
转载: http://blog.csdn.net/zzjjiandan/article/details/8372617 一. 获取当前系统时间和日期并格式化输出: import java.util.D ...
- JAVA获取当前系统时间System.currentTimeMillis()
System.currentTimeMillis()产生一个当前的毫秒,这个毫秒其实就是自1970年1月1日0时起的毫秒数,Date()其实就是相当于Date(System.currentTimeMi ...
- JAVA获取当前系统时间System.currentTimeMillis()以及获取运行时间
System.currentTimeMillis()产生一个当前的毫秒,这个毫秒其实就是自1970年1月1日0时起的毫秒数,Date()其实就是相当于Date(System.currentTimeMi ...
- java获取当前系统时间
阿里巴巴推荐 Timestamp d = new Timestamp(System.currentTimeMillis()); 唯一的好处就是除了Timestamp,没有再新建什么了
- 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/python中获取当前系统时间,并与字符串相互转换格式,或者转化成秒数,天数等整数
java转换成秒数 Date类有一个getTime()可以换回秒数,例如: public class DateToSecond { public static void main(String[] a ...
- java 获取当前系统系时间
//SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式 SimpleDateFo ...
随机推荐
- 【iOS开发】IOS界面开发使用viewWithTag:(int)findTag方法获取界面元素
http://blog.csdn.net/lxp1021/article/details/43952551 今天在开发OS界面的时候,遇到通过界面UIview viewWithTag:(int)fin ...
- 简单理解DES加密算法
数据加密标准(Data Encryption Standard,DES)是当前使用最广泛的加密体制,对于任意的加密方案,总有两个输入:明文和密钥. 明文是64bits,密钥是56bits 加密过程就是 ...
- 多线程 调用多线程的方法 Runtime与ProcessBuilder
一般我们使用Java运行其他类中的方法的时候,无论是静态调用还是动态调用,都是在当前的进程中执行的.也就是只有一个Java虚拟机实例在运行.有时候需要通过Java代码启动多个Java子进程,这样做会消 ...
- Java IO 之 RandomAccessFile 操作文件内容
RandomAccessFile类实现对文件内容的随机读写 文件内容的随机操作,重难点在于字符操作,具体查看API package org.zln.io.file; import java.io.IO ...
- [Leetcode] Remove duplicate from sorted list ii 从已排序的链表中删除重复结点
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numb ...
- bcc
#include<bits/stdc++.h> using namespace std; #define mxn 510 struct E{ int from,to; }; int dfn ...
- ubuntu下使用sudo 出现unable to resolve host 解决方法
Linux 环境, 假设这台机器名字叫dev(机器的hostname), 每次执行sudo 就出现这个警告讯息:sudo: unable to resolve host dev虽然sudo 还是可以正 ...
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) A
A. Little Artem and Presents time limit per test 2 seconds memory limit per test 256 megabytes input ...
- POJ2516:Minimum Cost(最小费用最大流)
Minimum Cost Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 19088 Accepted: 6740 题目链 ...
- Android 对Layout_weight属性完全解析以及使用ListView来实现表格
用在linearlayout 如果我们想要按照权重比例来分配LinearLayout,我们需要将其宽度设置为0dip http://blog.csdn.net/xiaanming/article/de ...