format date from 14 aug to YYYYMMDD(将日期从 8 月 14 日格式化为 YYYYMMDD)
问题描述
将日期 2011 年 8 月 14 日更改为格式 20110814 .. 我如何在 java 中做到这一点?
Change the date 14 aug 2011 to the format 20110814 .. how can i do that in java ?
这里 14aug 是一个字符串 ... String date="14aug";
Here 14aug is a string ... String date="14aug";
推荐答案
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
String yyyyMMdd = sdf.format(date);
参考:java.text.SimpleDateFormat
更新:精英绅士的问题很重要.如果你以 String
开头,那么你应该首先解析它以获取上例中的 date
对象:
Update: the question by The Elite Gentleman is important. If you start with a String
, then you should first parse it to obtain the date
object from the above example:
Date date = new SimpleDateFormat("dd MMM yyyy").parse(dateString);
这篇关于将日期从 8 月 14 日格式化为 YYYYMMDD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将日期从 8 月 14 日格式化为 YYYYMMDD
基础教程推荐
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- 降序排序:Java Map 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01