之前发现自己开发的测试平台中,总是在乱发邮件。明明不应该发的邮件,怎么又在发。
后来才发现,我自己记录时间类型的时候,记录错了
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()的更多相关文章

  1. java中时间的获取(二)

    java中时间的获取2 /** * 获取数据库操作记录时间 */ public static String getOpreateDbTime() { Calendar c = Calendar.get ...

  2. Java中时间日期格式化

    1.与日期时间相关的类:      第一:java.util.Date;                           将时间作为一个整体使用.处理时,使用Date类较为简便      第二:j ...

  3. Java中时间API使用详解

    目录 Java中时间API使用详解 1. 时区概念 2. 几种常见的时间 3. 时间戳 4. Java中的时间API 5. Java8中新添加的时间API 6. 在东八区的机器上获得美国时间 Java ...

  4. java中时间类型的问题

    时间类型:System.currentTimeMillis() 获得的是自1970-1-01 00:00:00.000 到当前时刻的时间距离,类型为longimport java.sql.Date d ...

  5. 【java】JDK1.8时间日期库 新特性 所有java中时间Date的使用

    除了lambda表达式,stream以及几个小的改进之外,Java 8还引入了一套全新的时间日期API,在本篇教程中我们将通过几个简单的任务示例来学习如何使用java 8的这套API.Java对日期, ...

  6. Java中时间格式处理,指定N天/小时等之后的时间

    1)根据当前时间,获取具体的时刻的时间 N天前 M小时之前 可用 new Date().getTime() - 24 * 60 * 60 * 1000*N[N天之前]的方法来获取处理时间之后的具体的值 ...

  7. Java中时间方法大全01(持续更新)

    下面这些方法都可以封装到一个工具类中 /** * 获取当前时间的时间戳 */ public static int getCurrentTimeIntValue() { return (int) (Sy ...

  8. java中时间比较

    package com.newtouch.test; import java.text.SimpleDateFormat;import java.util.Date; public class Tim ...

  9. JAVA中时间格式转换

    1.将任意日期格式的字符串转换为指定格式的字符串 //默认格式 String s1 = "20190110133236"; //给定格式 String s2 = "201 ...

随机推荐

  1. [LeetCode] 221. Maximal Square _ Medium Tag: Dynamic Programming

    Given a 2D binary matrix filled with 0's and 1's, find the largest square containing only 1's and re ...

  2. #C++初学记录(算法4)

    A - Serval and Bus It is raining heavily. But this is the first day for Serval, who just became 3 ye ...

  3. Webform和MVC,为什么MVC更好一些?(转)

    转自http://www.admin10000.com/document/5277.html 前言 如果你看了最近微软的议程,你会发现他们现在的焦点除了MVC,还是MVC.问题在于为什么微软如此热衷于 ...

  4. CTC(Connectionist Temporal Classification)介绍

    CTC解决什么问题 CTC,Connectionist Temporal Classification,用来解决输入序列和输出序列难以一一对应的问题. 举例来说,在语音识别中,我们希望音频中的音素和翻 ...

  5. mysql事务(二)——控制语句使用

    事务控制 一般来说,mysql默认开启了事务自动提交功能,每条sql执行都会提交事务.可以使用如下语句关闭事务自动提交功能. show session variables like 'autocomm ...

  6. mysql B+Tree索引

    原文地址:http://blog.codinglabs.org/articles/theory-of-mysql-index.html 数据结构及算法基础 索引的本质 MySQL官方对索引的定义为:索 ...

  7. 关于JavaScript的数组随机排序

    昨天了解了一下Fisher–Yates shuffle费雪耶兹随机置乱算法,现在再来看看下面这个曾经网上常见的一个写法: function shuffle(arr) { arr.sort(functi ...

  8. Linux(CentOS)下同时启动两个tomcat

    问题背景:在配置nginx时,配置了两个tomcat,tomcat01和tomcat02,改了tomcat02中server.xml的端口,可是还是启动不起来. 解决方法: 一.编辑环境变量: 1 v ...

  9. 在IBM学到的东西,到底对我的程序生涯产生了多大的影响

    我和很多人交流过一个有趣的现象,那就是刚毕业到30岁这段时间,会觉得时间过得很慢,总觉得自己还很年轻,但是一旦过了30岁,时间就如白驹过隙,一年又一年飞逝而过. 我自己也是,眼瞅着毕业快15年了,15 ...

  10. 03: MySQL基本操作

    MySQL其他篇 目录: 参考网站 1.1 MySQL 三种数据类型(数值,字符串,日期) 1.2 MySQL常用增删改查命令 1.3 删除,添加或修改表字段 1.4 MySQL外键关联(一对多) 1 ...