Java SimpleDateFormat.format(日期)配置

时间:2013-08-10 14:22:17

标签: java calendar timezone simpledateformat zk

我正在使用Zk-Calendar开发Google-Calendar我有一个关于java.text.SimpleDateFormat的问题,这里有一些代码

1)。如何在day中获取monthfirst letter uppercase is this possible

这是我到目前为止使用的代码。

private final SimpleDateFormat dformat = new SimpleDateFormat("EEEE dd-MMMMM-yyyy HH:mm:ss a");
private void printDateTester() 
{
    final Locale VENEZUELA_LOCALE = new Locale("es","VE");
    Locale locale = Locale.getDefault();
    System.out.println(locale.getDisplayCountry()+" "+locale.getCountry());//prints United States US
    System.out.println(VENEZUELA_LOCALE.getDisplayCountry()+" "+VENEZUELA_LOCALE.getCountry());//prints Venezuela VE
    final Calendar TODAY_US  = Calendar.getInstance(locale);
    final Calendar TODAY_VEN = Calendar.getInstance(VENEZUELA_LOCALE);
    System.out.println(dformat.format(TODAY_US.getTime())); //prints sábado 10-agosto-2013 11:07:55 AM  
    System.out.println(dformat.format(TODAY_VEN.getTime()));//prints sábado 10-agosto-2013 11:07:55 AM    
}  

它打印的内容类似sabado 10-agosto-2013 09:42:24 AM in english something like saturday 10-august-2013,但我希望Saturday 10-August-2013 09:42:24 AM之类的内容可能吗?

任何想法都非常感谢。

更新

我使用Locale.US创建了2个SimpleDateFormats 1,使用Venezuela LocaleSpain Locale创建了US Uppercase版本,但Venezuela and Spain lowercase locales在Spanish打印,但我需要在final Locale VENEZUELA_LOCALE = new Locale("es","VE"); Locale locale = Locale.getDefault(); final SimpleDateFormat dformatI = new SimpleDateFormat("EEEE dd-MMMMM-yyyy HH:mm:ss a",VENEZUELA_LOCALE); final SimpleDateFormat dformatII = new SimpleDateFormat("EEEE dd-MMMMM-yyyy HH:mm:ss a",Locale.US); Locale: Venezuela VE print: domingo 11-agosto-2013 09:24:25 AM Locale: United States US print: Sunday 11-August-2013 09:24:25 AM 中显示数据为什么会这样?

{{1}}

1 个答案:

答案 0 :(得分:1)

您是否尝试过在DateTime格式对象中设置Locale:

    private final SimpleDateFormat dformat = new SimpleDateFormat("EEEE dd-MMMMM-yyyy HH:mm:ss a",Locale.US);

并非所有语言都遵循美国标准(大写日期和月份名称)。因此,期望java DateTimeFormat 的输出值是什么。

您可以在以下问题中找到这个有趣的讨论

How to control the capitalization of month and day names returned by DateFormat?