将日期格式从 php 转换为 Java?

Convert date format from php to Java?

我正在开发流媒体 Android 应用程序,我必须将一些 php 代码转换为 java。 如何将此日期格式从 php 转换为 java?

$today = gmdate("n/j/Y g:i:s A");

这个date format in php是这样解释的:

n: Numeric representation of a month, without leading zeros

j: Day of the month without leading zeros

Y: A full numeric representation of a year, 4 digits

g: 12-hour format of an hour without leading zeros

i: Minutes with leading zeros

s: Seconds, with leading zeros

A: Uppercase Ante meridiem and Post meridiem - AM/PM

和同样的date format in java是这样的:

SimpleDateFormat simpleDateFormat = new SimpleDateFormat("M/d/yyyy h:mm:ss a");
String today = simpleDateFormat.format(new Date());

要从 PHP 日期字符串中获取新的 java.util.Date 对象,请在 Java:

String phpDateString = "7/24/2016 12:21:44 am";

SimpleDateFormat sdf = new SimpleDateFormat("M/d/yyyy h:mm:ss a");
Date javaDate = sdf.parse(phpDateString);

System.out.println(javaDate);
System.out.println(sdf.format(javaDate));

输出:

Sun Jul 24 00:21:44 CEST 2016
7/24/2016 12:21:44 AM

OP 的自我回答提供了很多信息,但它在 Java 表达式中有错误(小写 h 持续 am/pm 小时)并且没有包含实际代码将 PHP 字符串解析为 Java Date 对象,这是原始问题。