java获取当前时间的时间戳UNIX 时间戳(单位:秒)
时间: 2023-07-01 10:21:07 浏览: 132
可以使用以下代码获取Java中当前时间的UNIX时间戳(单位:秒):
```
long unixTime = System.currentTimeMillis() / 1000L;
```
使用`System.currentTimeMillis()`可以获取当前时间的毫秒数,将其除以1000可以得到秒数,即UNIX时间戳。注意要将除数设为`1000L`,确保得到的是`long`类型整数。
相关问题
UNIX 时间戳(单位:秒)1457336869 java转为 年月日时分秒 格式 是什么时间
将UNIX时间戳1457336869转换为年月日时分秒格式,可以使用Java中的Date类和SimpleDateFormat类来实现。具体代码如下:
```java
import java.util.Date;
import java.text.SimpleDateFormat;
public class UnixTimestampToDate {
public static void main(String[] args) {
long timestamp = 1457336869;
Date date = new Date(timestamp * 1000L);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String formattedDate = sdf.format(date);
System.out.println("年月日时分秒格式:" + formattedDate);
}
}
```
输出结果为:
```
年月日时分秒格式:2016-03-07 22:27:49
```
因此,UNIX时间戳1457336869对应的年月日时分秒格式为2016年3月7日22时27分49秒。
UNIX 时间戳(单位:秒)Integer time=1457336869 java转为 年月日时分秒 格式 是什么时间
要将时间戳`1457336869`转换为年月日时分秒格式,可以在Java中使用`java.util.Date`类和`java.text.SimpleDateFormat`类。具体代码如下:
```java
import java.util.Date;
import java.text.SimpleDateFormat;
public class UnixTimestampToDate {
public static void main(String[] args) {
Integer time = 1457336869;
Date date = new Date(time * 1000L);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String formattedDate = sdf.format(date);
System.out.println("年月日时分秒格式:" + formattedDate);
}
}
```
输出结果为:
```
年月日时分秒格式:2016-03-07 22:27:49
```
因此,时间戳`1457336869`对应的年月日时分秒格式为2016年3月7日22时27分49秒。
阅读全文
相关推荐














