当前位置:网站首页>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();
边栏推荐
- Mathematical modeling contest for graduate students - optimal application of UAV in rescue and disaster relief
- SQL injection bypass (I)
- 美摄云服务方案:专为轻量化视频制作场景打造
- Gaussian distribution, linear regression, logistic regression
- 高斯分布Gaussian distribution、线性回归、逻辑回归logistics regression
- TiDB的使用限制
- ORA-00909: 参数个数无效,concat引起
- Once spark reported an error: failed to allocate a page (67108864 bytes), try again
- Crawler learning 5--- anti crawling identification picture verification code (ddddocr and pyteseract measured effect)
- NoViableAltException([email protected][2389:1: columnNameTypeOrConstraint : ( ( tableConstraint ) | ( columnNameT
猜你喜欢
随机推荐
The SCP command is used in the expect script. The perfect solution to the problem that the SCP command in the expect script cannot obtain the value
2022 CISP-PTE(一)文件包含
Unrecognized VM option ‘‘
extendible hashing
Cloud-Native Database Systems at Alibaba: Opportunities and Challenges
面试官:大量请求 Redis 不存在的数据,从而打倒数据库,你有什么方案?
[QT notes] basic use of qregularexpression in QT
426 binary tree (513. find the value in the lower left corner of the tree, 112. sum of paths, 106. construct a binary tree from the middle order and post order traversal sequence, 654. maximum binary
Active learning
网关状态检测 echo request/reply
OPPO面试整理,真正的八股文,狂虐面试官
快速实现蓝牙iBeacn功能详解
The number of query results of maxcompute SQL is limited to 1W
Redis 缓存穿透、缓存击穿、缓存雪崩
Modeling competition - optical transport network modeling and value evaluation
POI 替换docx中的文字和图片
Unrecognized VM option ‘‘
JVM对象组成和存储
Gaussian distribution, linear regression, logistic regression
Scala advanced_ Member access modifier









