当前位置:网站首页>日期工具类
日期工具类
2022-07-21 11:09:00 【编程奥特曼.】
package itheima_02;
import java.util.Date;
public class DateDemo {
public static void main(String[] args) {
//创建日期对象
Date d = new Date();
String s1 = DateUtils.dateTOString(d,“yyy年MM月dd日 HH:mm:ss”);
System.out.println(s1);
String s2 = DateUtils.dateTOString(d, "yyy年MM月dd日");
System.out.println(s2);
String s3 = DateUtils.dateTOString(d, "HH:mm:ss");
System.out.println(s3);
System.out.println("--------");
String s ="2048-08-09 12:12:12";
Date dd = DateUtils.stringToDate(s, "yyy-MM-dd HH:mm:ss");
System.out.println(dd);
}
}
package itheima_02;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/*工具类
构造方法私有
成员方法静态
*/
public class DateUtils{
private static Date date;
private static String format;
private DateUtils(){
}
/*
把日期转为指定格式的字符串
返回值类型 String
参数: Date date, String format
*/
public static String dateTOString(Date date,String format){
SimpleDateFormat sdf = new SimpleDateFormat(format);
String s = sdf.format(date);
return s;
}
/*把字符解析为指定格式的日期
返回值类型: Date
参数: String s String format
*/
public static Date stringToDate(String s ,String format){
SimpleDateFormat sdf = new SimpleDateFormat(format);
Date d = null;
try {
d = sdf.parse(s);
} catch (ParseException e) {
e.printStackTrace();
}
return d;
}
}
边栏推荐
- Likeshop single merchant SaaS mall system opens unlimited
- 代码管理(新手)
- 怎样让全彩LED显示屏变的节能环保?
- taokeeper 环境搭建
- flash多开
- "F5g+eiot" build the energy Internet of things and help the data service of the power Internet of things
- Part 109 liquid in compound
- SAP ABAP parsing function text of Excel file_ CONVERT_ XLS_ TO_ SAP single step analysis
- 【2022年中总结】我走得很慢,但我从不后退
- 对话ACE第四期:分布式数据库未来发展的挑战和机遇
猜你喜欢
Intel assembler programming - integer arithmetic instructions (Part 1)
The training accuracy is comparable to alphafold2, and the speed is doubled. The helixfold training and reasoning code of the propeller is fully open source
多模态模型 CLIP4Clip 带你实现文本与视频互搜
“F5G+EIoT“构建能源物联网,助力电力物联网数据服务
Techempower web框架性能测试第21轮结果发布--asp.net core继续前进
Design and application of prepaid platform on power reform policy
Application of DC distribution system products at the end of data center
Ansvc reactive power compensation device helps an environmental protection energy project in Jiangsu
腾讯浏览器服务TBS使用
训练精度媲美 AlphaFold2、速度翻倍,飞桨螺旋桨HelixFold训练和推理代码全面开源...
随机推荐
Vs2017 offline installation
What is REITs? Excuse me, is it safe to open a stock account by mobile phone?
Oneinstack安装与配置PHP 8.1和MySQL 8.0-Oneinstack建站新手教程
Design and application of prepaid platform on power reform policy
[深入研究4G/5G/6G专题-39]: URLLC-10-《3GPP URLLC相关协议、规范、技术原理深度解读》-3-如何区分URLLC业务?网络切片的架构与技术详解
How to make the demand unable to go online smoothly as scheduled (V) business acceptance stage
La précision de l'entraînement est comparable à alphafold2, la vitesse est doublée, l'hélice volante Helix fold entraînement et le Code d'inférence sont entièrement open source...
(数论板子)约数个数与约数之和
一招教你拿捏网上视频
浏览器缓存机制解析
SAP ABAP 解析 excel 文件的函数 TEXT_CONVERT_XLS_TO_SAP 单步执行分析
Comptroller in compound, part 105
Learning notes of Stanford CV course (I)
Implementing DDD based on ABP -- domain service, application service and dto practice
第107篇 Compound 中的 InterestRateModel
yii2渲染自定义模板文件
[译] PostgreSQL 怎么决定PG 的备份策略
A lesson in blood NPM package lock The bloody rain caused by JSON
Part 100 library contract compatible with Eth and erc20
第103篇 Compound 中的小数