Java-SimpleDateFormat将12:19:00解析为00:19:00 [英] Java - SimpleDateFormat parses 12:19:00 to 00:19:00

查看:132
本文介绍了Java-SimpleDateFormat将12:19:00解析为00:19:00的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试解析一个字符串,但是输出看起来不正确:
下面是我的代码。

I am trying to parse a string to date, but the output look incorrect: Below is my code.

public static void main(String[] args){      
  Date startDate = new Date();      
  DateFormat formatter = new SimpleDateFormat("dd.MM.yyyy hh:mm:ss");

  try {
    startDate = (Date) formatter.parse("07.10.2012 12:19:24");
  } catch (ParseException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  }

  System.out.println("Formatted Date " + startDate.toString());
}

程序输出:

格式化日期十月07日 00 :19:24 IST 2012

Program Output:
Formatted Date Sun Oct 07 00:19:24 IST 2012

预期产量:

格式化日期十月07 12 :19:24 IST 2012

Expected Output:
Formatted Date Sun Oct 07 12:19:24 IST 2012

推荐答案

您可能希望使用24h格式而不是12h格式...

You might want to use 24h format instead of 12h format...


H一天中的小时数(0-23)数字0

H Hour in day (0-23) Number 0

h上午/下午的小时数(1-12)数字12

h Hour in am/pm (1-12) Number 12

是的,格式字符区分大小写。

Yes, formatting characters are case sensitive.

这篇关于Java-SimpleDateFormat将12:19:00解析为00:19:00的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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