在java中要将字符串转换为日期格式,则要使用SimpleDateFormat类中的parse方法 format方法传入的参数格式含义说明: yyyy:表示四位年 MM:表示月份 dd:表示日子 HH
来源:互联网 发布:mac 数据库管理工具 编辑:程序博客网 时间:2024/04/28 16:44
在java中要将字符串转换为日期格式,则要使用SimpleDateFormat类中的parse方法
format方法传入的参数格式含义说明:
yyyy:表示四位年
MM:表示月份
dd:表示日子
HH:表示24小时制小时
hh:表示12小时制小时
mm:表示分钟
ss:表示秒
具体请看例子:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date date = sdf.parse("2016-06-06");
System.out.println(sdf.format(date));
输出结果为:2016-06-06
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = sdf.parse("2016-06-06 16:24:50");
System.out.println(sdf.format(date));
输出结果为:2016-06-06 16:24:50
public static void main(String[] args) throws ParseException {
//日期时间格式:yyyy-MM-dd hh:mm:ss
String time ="1900-02-21";
//将字符串转换为日期和时间
SimpleDateFormat dateformat = new SimpleDateFormat("yyyyMMdd");
//生成的日期和时间
Date date = dateformat.parse("2016-06-06");
//Date date = dateformat .parse(time);
//String data=
//System.out.println();
System.out.println(dateformat.format(date));
System.out.println(date);
}
- 在java中要将字符串转换为日期格式,则要使用SimpleDateFormat类中的parse方法 format方法传入的参数格式含义说明: yyyy:表示四位年 MM:表示月份 dd:表示日子 HH
- 将Json中的datetime的UTC表示形式转换为:"yyyy-MM-dd"或"yyyy-MM-dd HH:mm:ss"字符串表示形式
- 将Json中的datetime的UTC表示形式转换为:"yyyy-MM-dd"或"yyyy-MM-dd HH:mm:ss"字符串表示形式
- Java日期格式转换-yyyy-MM-dd HH:mm:ss转换为yyyy-MM-dd
- 时间戳格式化转换为日期格式,date.Format('yyyy/MM/dd hh:mm:ss')
- 将“yyyyMMdd”格式的时间字符串转换为“yyyy-MM-dd HH:mm:ss”格式(Java)
- [乐意黎原创] 时间格式 yyyy-MM-dd'T'HH:mm:ss.SSSZ 中的T和Z表示什么
- 将yyyy-dd-MM hh:mm:ss字符串格式的时间转换为毫秒
- 日期格式转换字符串格式(toString("yyyy-MM-dd hh:mm:ss"))报错.
- java中“dd/MMM/yyyy:HH:mm:ss”转换为格式“yyyy-MM-dd HH:mm:ss”
- 日期格式yyyy-MM-dd HH:mm:ss的解释
- java将日期格式字符串2015-08-05T09:40:00+08:00转换为yyyy-MM-dd HH:mm:ss
- js将字符串时间格式yyyy-MM-dd hh:mm:ss 转换为long
- js将字符串时间格式yyyy-MM-dd hh:mm:ss 转换为long
- 时间转换的好用方法(好招1)//Date date = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse("2007-09-21 11:00:10.0100");
- 将时间转换成yyyy-MM-dd HH:mm:ss的格式字符串
- 将时间转换成yyyy-MM-dd HH:mm:ss的格式字符串
- DateTime与yyyy-MM-dd HH:mm格式的字符串相互转换
- Spring框架简单理解
- c#连接到sql server2008数据库
- spring-cloud-netflix编译错误
- Codeforces Codeforces Round #432 (Div. 2 D ) Arpa and a list of numbers
- lintcode:旋转字符串
- 在java中要将字符串转换为日期格式,则要使用SimpleDateFormat类中的parse方法 format方法传入的参数格式含义说明: yyyy:表示四位年 MM:表示月份 dd:表示日子 HH
- Scala-Spark digamma stackoverflow问题
- JavaWeb 自定义标签&EL自定义函数
- 【线段树 && 离线处理 && 维护区间规定下标的和】HDU
- 浅谈Android开发中的MVVM模式及与MVP和MVC的区别
- sqlServer数据库备份
- POI常用操作
- oracle常用语句
- sql左右连接