当前位置:网站首页>Date database date strings are converted to and from each other
Date database date strings are converted to and from each other
2022-06-27 06:38:00 【YUELEI118】
date :java.util.Date
Database date :java.sql.Date
date Convert to Database date
- a key : Dated
getTime()Get timestamp , Convert to database date
// util.Date --> sql.Date
java.util.Date nowDate1 = new java.util.Date();
java.sql.Date sqlDate = new java.sql.Date(nowDate1.getTime());
System.out.println("sqlDate = " + sqlDate);
Database date Convert to date
- a key : Of database date
getTime()Get timestamp , Convert to date
java.util.Date Date = new java.util.Date(sqlDate.getTime());
date Convert to character string
- a key :SimpleDateFormat Class format() Method
// util.Date --> String
java.util.Date nowDate = new java.util.Date();
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd"); // Formatting tool
SimpleDateFormat sf1 = new SimpleDateFormat("yyyy year MM month dd Japan HH spot mm branch ss second ");
String format = sf.format(nowDate);
System.out.println("format = " + format);
String format1 = sf1.format(nowDate);
System.out.println("format1 = " + format1);
character string Convert to date
- a key : The format of the parameter defined in the formatting tool must be the same as that of the string
SimpleDateFormat sf = new SimpleDateFormat("yyyy/MM/dd"); // Formatting tool
String stDate = "2020/01/01"; // character string
java.util.Date parseDate = sf.parse(stDate);
System.out.println("parseDate = " + parseDate);
SimpleDateFormat sf1 = new SimpleDateFormat("yyyy year MM month dd Japan HH spot mm branch ss second ");
String stDate1 = "2021 year 3 month 20 Japan 19 spot 20 branch 30 second ";
java.util.Date parseDate1 = sf1.parse(stDate1);
System.out.println("parseDate1 = " + parseDate1);
Database date Convert to character string
- It is the same method as converting a date to a string
java.util.Date nowDate = new java.util.Date();
java.sql.Date sqlDate = new java.sql.Date(nowDate.getTime());
SimpleDateFormat sf = new SimpleDateFormat("yyyy/MM/dd"); // Formatting tool
SimpleDateFormat sf1 = new SimpleDateFormat("yyyy year MM month dd Japan HH spot mm branch ss second ");
String format = sf.format(sqlDate);
String format1 = sf1.format(sqlDate);
System.out.println("format = " + format);
System.out.println("format1 = " + format1);
- Of database date toString() Method
The output only has month, year and day , Can't make time, minutes and seconds
java.sql.Date sqlDate = new java.sql.Date(new java.util.Date().getTime());
System.out.println("sqlDate = " + sqlDate);
character string Convert to Database date
- At present, it will not be directly transferred to , Only through date transit
LocalDate And sql.Date transformation
sql.Date Class about LocalDate There are only these two methods
LocalDate Convert to Database date
- Only about... In the database date date No datetime, Want to display hours, minutes and seconds , Probably still util.date
LocalDate nowLocalDate = LocalDate.now();
Date date = Date.valueOf(nowLocalDate);
System.out.println("date = " + date);
Database date Convert to LocalDate
LocalDate localDate = sqlDate.toLocalDate();
边栏推荐
猜你喜欢

JVM整体结构解析

Active learning

427- binary tree (617. merge binary tree, 700. search in binary search tree, 98. verify binary search tree, 530. minimum absolute difference of binary search tree)

Ahb2apb bridge design (2) -- Introduction to synchronous bridge design
[email protected][2389:1: columnNameTypeOrConstraint : ( ( tableConstraint ) | ( columnNameT"/>NoViableAltException([email protected][2389:1: columnNameTypeOrConstraint : ( ( tableConstraint ) | ( columnNameT

The fourth question of the 299th weekly match 6103 Minimum fraction of edges removed from the tree

JVM object composition and storage

Quick realization of Bluetooth ibeacn function

Modeling competition - optical transport network modeling and value evaluation

thrift
随机推荐
AHB2APB桥接器设计(2)——同步桥设计的介绍
技术人员创业一年心得
LeetCode 0086.分隔链表
427- binary tree (617. merge binary tree, 700. search in binary search tree, 98. verify binary search tree, 530. minimum absolute difference of binary search tree)
快速实现蓝牙iBeacn功能详解
观测电机转速转矩
[QT notes] basic use of qregularexpression in QT
Keep 2 decimal places after multiplying SQLSEVER fields
JVM的垃圾回收机制
MPC control of aircraft wingtip acceleration and control surface
vscode korofileheader 的配置
2022 CISP-PTE(一)文件包含
高斯分布Gaussian distribution、线性回归、逻辑回归logistics regression
2018 mathematical modeling competition - special clothing design for high temperature operation
JVM class loading mechanism
Inter thread wait and wake-up mechanism, singleton mode, blocking queue, timer
网关状态检测 echo request/reply
美摄云服务方案:专为轻量化视频制作场景打造
One year's experience of technical personnel in Entrepreneurship
可扩展哈希