如何在java中将'dd/mm/yyyy hh:mm:ss am/pm'转换为hh:mm:ss(没有am或pm)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21180434/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 07:09:08  来源:igfitidea点击:

How to convert 'dd/mm/yyyy hh:mm:ss am/pm' to hh:mm:ss (without am or pm) in java?

javadatetimeformat

提问by user3205610

I want the convert the string like 1/15/2014 9:57:03 AMor 1/15/2014 5:49:39 PMto 9:57:03and 17:49:39

我希望将字符串像1/15/2014 9:57:03 AM或转换1/15/2014 5:49:39 PM9:57:0317:49:39

回答by ??????? ?????

You should see this in the doc doc SimpleDateFormat

您应该在 doc doc Si​​mpleDateFormat 中看到这一点

回答by Polyethylene

SimpleDateFormat format = new SimpleDateFormat("dd/mm/yyyy hh:mm:ss a", Locale.US);
Date date = format.parse("1/15/2014 9:57:03 AM");
format = new SimpleDateFormat("HH:mm:ss");
String dateString = format.format(date);

BTW, use Google next time

BTW,下次用谷歌