将日期从 8 月 14 日格式化为 YYYYMMDD [英] format date from 14 aug to YYYYMMDD

查看:27
本文介绍了将日期从 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆