案例:
@Test
void bbb(){
String format = "MMM d, yyyy hh:mm:ss a zzz";
// 创建“英文/美国”的Locale
Locale localeUS = new Locale("en", "US");
Date date = new Date();
String format2 = DateUtil.format(date, format);
System.out.println("format2 = " + format2);
SimpleDateFormat formatA = new SimpleDateFormat(format, localeUS);
String format1 = formatA.format(date);
System.out.println("format2 = " + format1);
// (四月 14, 2023 11:34 上午 +0800) 格式:"MMM d, yyyy hh:mm aa Z"
// (四月 14, 2023 11:36:22 上午 +0800) 格式:"MMM d, yyyy hh:mm:ss aa Z"
// (四月 14, 2023 06:01:09 下午 CST) 格式:"MMM d, yyyy hh:mm:ss a zzz"
// (Apr 14, 2023 06:21:20 PM CST) 格式:"MMM d, yyyy hh:mm:ss a zzz" 注意:需要进行US的地区才能得到
// 创建“简体中文”的Locale
Locale localeCN = Locale.SIMPLIFIED_CHINESE;
// 获取“简体中文”对应的date字符串
String cn = DateFormat.getDateInstance(DateFormat.MEDIUM, localeCN).format(date);
// 获取“英文/美国”对应的date字符串
String us = DateFormat.getDateInstance(DateFormat.MEDIUM, localeUS).format(date);
System.out.printf("cn=%s\nus=%s\n", cn, us);
}