簡體   English   中英

使用SimpleDateFormat解析日期

[英]Parsing date with SimpleDateFormat

為什么以下給出錯誤:

    DateFormat formatter1 = new SimpleDateFormat("E, MMM d");
    formatter1.setTimeZone(TimeZone.getTimeZone("America/New_York"));

    formatter1.parse("Tue, Nov 26");

我不明白為什么它不起作用。

您應該在格式化程序中設置一個Locale ,在該Locale中英語是用幾個月拼寫的,否則,它將使用默認的Locale

SimpleDateFormat(String pattern)

使用給定的模式和默認語言環境的默認日期格式符號構造一個SimpleDateFormat

即:

DateFormat formatter1 = new SimpleDateFormat("E, MMM d", Locale.US);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM