我写的下个这个代码想得到如下这样的效果。如:22:10 PM
Date date = new Date();
String strDateFormat = "HH:mm a";
DateFormat sdf = new SimpleDateFormat(strDateFormat);
System.out.println(sdf.format(date));
但是这个执行出来的结果去是 22:10 下午
请教高手想得到我说的那种结果该如何写
Date date = new Date();
String strDateFormat = "HH:mm a";
DateFormat sdf = new SimpleDateFormat(strDateFormat);
System.out.println(sdf.format(date));
但是这个执行出来的结果去是 22:10 下午
请教高手想得到我说的那种结果该如何写
你把Locale设成US试试.public static final DateFormat getTimeInstance(int style,
Locale aLocale)
Gets the time formatter with the given formatting style for the given locale. Parameters:
style - the given formatting style. For example, SHORT for "h:mm a" in the US locale.
aLocale - the given locale.
Returns:
a time formatter.
---------------------------------------------------------------------package com.csdn;import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;/**
* @author xiaotang E-mail: [email protected]
* @version1.00 创建时间:Mar 29, 2009 5:06:15 AM 类说明:
*/public class SimpleDateFormateTest { /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String format = "h:mm a";
Date date = new Date(); SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.US);
String time = sdf.format(date);
System.out.println(time); }}
------------------------------------------------------------------
不知不觉,我喜欢上了CSDN了,让我学到了许多没有遇到的问题
System.out.println(sdf.format(new Date()););