Java 中时间处理 System.currentTimeMillis()
之前发现自己开发的测试平台中,总是在乱发邮件。明明不应该发的邮件,怎么又在发。
后来才发现,我自己记录时间类型的时候,记录错了
24小时制要用大写的HH 比如
SimpleDateFormat dtf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss@SSS");
而我用了小写的hh的格式~~~ 还有时间存入DB中,是直接使用数据库中的函数,比如在SQl中锁定函数
mysql中,insert tablename () values (now())
sqlserver中, insert tablename () values (getdate())
还是自己定义一个时间string类型的参数,比如creationdt,然后给它一个默认的格式,insert tablename() values (creationdt)
如果只是一个数据库交互,后期不更改使用的数据库,用数据库中的函数也是可以的,还可以减少开发和测试的工作量
如果一个产品,既要在mysql上可以运行,后期客户说想迁移到sqlserver数据库,也要可以执行,那就是要定义一下,不然换数据库中自然会报错 import org.junit.Test;
import java.text.SimpleDateFormat;
import java.util.Date; public class EposReceiveApplicationTests { @Test
public void TestDate() throws Exception { Date dt= new Date();
long s=System.currentTimeMillis();
System.out.println(s);
long long1= 1559197504587L;
SimpleDateFormat dtf = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat dtf1 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss@SSS");
SimpleDateFormat dtf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss@SSS");
String sdate =dtf1.format(long1);
System.out.println(sdate); System.out.println(dtf.format(dt));
System.out.println(dtf1.format(dt));
System.out.println(dtf1.format(dt).toString());
System.out.println(dtf2.format(dt));
System.out.println(dtf2.format(dt).toString()); // Date -> String
Date date = new Date(System.currentTimeMillis());
System.out.println(dtf.format(date)); // String -> Date
String timeString = "2019-05-30 14:25:15";
Date newDate = dtf.parse(timeString);
System.out.println(newDate); } }
import org.junit.Test;
import java.text.SimpleDateFormat;
import java.util.Date; public class EposReceiveApplicationTests { @Test
public void TestDate() throws Exception { Date dt= new Date();
long s=System.currentTimeMillis();
System.out.println(s);
long long1= 1559197504587L;
SimpleDateFormat dtf = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat dtf1 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss@SSS");
SimpleDateFormat dtf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss@SSS");
String sdate =dtf1.format(long1);
System.out.println(sdate); System.out.println(dtf.format(dt));
System.out.println(dtf1.format(dt));
System.out.println(dtf1.format(dt).toString());
System.out.println(dtf2.format(dt));
System.out.println(dtf2.format(dt).toString()); // Date -> String
Date date = new Date(System.currentTimeMillis());
System.out.println(dtf.format(date)); // String -> Date
String timeString = "2019-05-30 14:25:15";
Date newDate = dtf.parse(timeString);
System.out.println(newDate); } }
Java 中时间处理 System.currentTimeMillis()的更多相关文章
- java中时间的获取(二)
java中时间的获取2 /** * 获取数据库操作记录时间 */ public static String getOpreateDbTime() { Calendar c = Calendar.get ...
- Java中时间日期格式化
1.与日期时间相关的类: 第一:java.util.Date; 将时间作为一个整体使用.处理时,使用Date类较为简便 第二:j ...
- Java中时间API使用详解
目录 Java中时间API使用详解 1. 时区概念 2. 几种常见的时间 3. 时间戳 4. Java中的时间API 5. Java8中新添加的时间API 6. 在东八区的机器上获得美国时间 Java ...
- java中时间类型的问题
时间类型:System.currentTimeMillis() 获得的是自1970-1-01 00:00:00.000 到当前时刻的时间距离,类型为longimport java.sql.Date d ...
- 【java】JDK1.8时间日期库 新特性 所有java中时间Date的使用
除了lambda表达式,stream以及几个小的改进之外,Java 8还引入了一套全新的时间日期API,在本篇教程中我们将通过几个简单的任务示例来学习如何使用java 8的这套API.Java对日期, ...
- Java中时间格式处理,指定N天/小时等之后的时间
1)根据当前时间,获取具体的时刻的时间 N天前 M小时之前 可用 new Date().getTime() - 24 * 60 * 60 * 1000*N[N天之前]的方法来获取处理时间之后的具体的值 ...
- Java中时间方法大全01(持续更新)
下面这些方法都可以封装到一个工具类中 /** * 获取当前时间的时间戳 */ public static int getCurrentTimeIntValue() { return (int) (Sy ...
- java中时间比较
package com.newtouch.test; import java.text.SimpleDateFormat;import java.util.Date; public class Tim ...
- JAVA中时间格式转换
1.将任意日期格式的字符串转换为指定格式的字符串 //默认格式 String s1 = "20190110133236"; //给定格式 String s2 = "201 ...
随机推荐
- Google面试题[一]
谷歌是不少IT人都想去的企业,那么在进入公司前,少不了面试笔试的测试.那么这里我们就总结了如下谷歌笔试题,并提供了一些参考答案.希望对您有用. 谷歌笔试题:判断一个自然数是否是某个数的平方.当然不能使 ...
- [Leetcode] 49. Group Anagrams_Medium
Given an array of strings, group anagrams together. Example: Input: ["eat", "tea" ...
- 2018-2019-2 网络对抗技术 20165324 Exp5:MSF基础应用
2018-2019-2 网络对抗技术 20165324 Exp5:MSF基础应用 MSF基础知识: MSF基础框架: 主要模块模块(Module).模块是指Metasploit框架中所使用的一段软件代 ...
- 从游戏开发到web前端——仅仅只是开始
文章开头,请允许我随便扯扯. 一来,开头从来都是最难写的,二来,描述我现在的心情和状态以及工作背景啥的,对于大家理解后面的内容也许会有所帮助~ 2012年211大学毕业,工作4年了,一直都是做游戏前端 ...
- js之数组排序
数组,大家都不陌生,只要是学编程的人都知道这个入门的数据结构,在js中也是有数组这个概念的,跟普通的数组一样只是定义的形式不同罢了.下面是一个数组的排序代码: <html> <hea ...
- SP Flash Tool New Version v5.1352.01
Friends, Sp Tool updated to new version with whole new revamped interface New SP Flash Tool 3.1352.0 ...
- 187. Repeated DNA Sequences(建立词典,遍历一遍 o(n))
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...
- js文本框字数限制
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- 虚拟机中安装mac系统
虚拟机安装就很简单了,傻瓜式安装,一直点击下一步就行,这里就不多说了. 所需要的配置: 虚拟机下载地址:链接:http://pan.baidu.com/s/1i45wXRf 密码:7c4x mac补丁 ...
- Web安全学习笔记之DES算法实例详解
转自http://www.hankcs.com/security/des-algorithm-illustrated.html 译自J. Orlin Grabbe的名作<DES Algorith ...