java - java中的日期格式

标签 java date format

      SimpleDateFormat sdf = new SimpleDateFormat("ddMMM", Locale.ENGLISH);

      try {

        sdf.parse(sDate);
      } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

我的日期格式是 04AUG2011,我想要 20110804。那么我该怎么做呢?

最佳答案

使用以下格式:

 SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd", Locale.ENGLISH);

我认为你需要区分解析和输出:

 SimpleDateFormat parseFormat = new SimpleDateFormat("MMMdd", Locale.ENGLISH);
 SimpleDateFormat outputFormat = new SimpleDateFormat("yyyyMMdd", Locale.ENGLISH);
 String dateStr = "06Sep";
 // parse with 06Sep format
 Date din = parseFormat.parse(dateStr);
 // output with 20101106 format
 System.out.println(String.format("Output: %s", outputFormat.format(din)));

关于java - java中的日期格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5220967/

相关文章:

mysql - DBeaver:以毫秒显示日期时间

Java AWT 线程

java - 设置布局宽度占屏幕总宽度的百分比

php - 将日期从数据库更改为数组

python - 重新索引并填写缺失的日期

date - ElasticSearch日期格式,使用严格错误

image - 色度信号是否向 YUV 中的亮度添加任何信息?

java - 将 Maven 依赖项部署到 S3 : No connector available

java - Weblogic 10 上的 Hibernate validator

date - HIVE - 按日期功能分组