SimpleDateFormat得到年月日格式的字符串,再转为int类型

news/2024/7/6 3:44:05 标签: SimpleDateFormat

1.年月日

public static void main(String[] args) {
    SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
    int nowDay = Integer.parseInt(df.format(System.currentTimeMillis()).toString());

    System.out.println(nowDay);//结果20181017
}

 

2.年月日时分秒

public static void main(String[] args) {
    SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
    Long nowDay = Long.parseLong(df.format(System.currentTimeMillis()).toString());

    System.out.println(nowDay);//结果20181017150714
}

3.获取时间戳,精确到秒

public static int getTimestamp() {
   int timestamp = 0;
   timestamp = (int) (System.currentTimeMillis() / 1000);
   return timestamp;
}

 


http://www.niftyadmin.cn/n/760918.html

相关文章

python如何调用c++numpy.ndarray代码_3.2Python数据处理篇之Numpy系列(二)--- ndarray数组的创建与变换...

[TOC]目录:1.ndarray数组的创建2.ndarray数组的变换(一)ndarray数组的创建1.从列表以元组中创建:.array(list/tuple).array(list/tuple,dytpe np.int32), dtype用于指名类型2.使用函数创建:(1).arange(n), 0~n-1 一维(2).ones(shape) 1(3).z…

阶乘与排列的例子(从n个元素中取m个元素组成互不相同并且不重复的三位数)

public static void main(String[] args) {//1.编写一个程序,输入n,求n!(用递归的方式实现)。4*3*2*14! 注:0!1System.out.println("4的阶乘为:" getFactorial(4));//2.编写一个程序&#xff0…

layui使用tips_使用layer.tips实现鼠标悬浮时触发事件提示消息实现

代码:你瞅啥!?过来试试!方法一:function show(id) {layer.tips("左边么么哒", "#"id"", {tips: [4, "#4794ec"]});}实现效果:如图所示,当鼠标悬浮在la…

FileReader读取文本内容

//3.编写一个程序,将text1.txt文件中的单词与text2.txt文件中的单词交替合并到text3.txt文件中。 // text1.txt文件中的单词用回车符分隔,text2.txt文件中用回车或空格进行分隔。 public static void main(String[] args) throws Exception{String[] a …

visio2013(64位)

链接:https://pan.baidu.com/s/1E7ZXV9Azmk3xLijTKC3DVA 提取码:elze

IDEA快捷键--选中多个相同内容并扩展选中内容

1.如何选中多行相同的内容,快捷键ctrlaltshiftj,如下图: 这里我们要选中这个文件所有行的 "IF NOT EXISTS",就先选中其中一个 "IF NOT EXISTS",然后用ctrlaltshiftj快捷键就可以选中所有了,此时如果编辑的话&…

mysql galera cluster实现vip_五大常见的MySQL高可用方案

1.概述我们在考虑MySQL数据库的高可用的架构时,主要要考虑如下几方面:1.1 如果数据库发生了宕机或者意外中断等故障,能尽快恢复数据库的可用性,尽可能的减少停机时间,保证业务不会因为数据库的故障而中断。1.2 用作备份…

重庆市2020年及2019年全科春季高考(单招)试题及答案:

链接:https://pan.baidu.com/s/1vvXDSsM20nqYYCAeIwtSvw 提取码:xans