How to determine day of week by passing specific date?

前端 未结 25 1824
夕颜
夕颜 2020-11-22 05:12

For Example I have the date: \"23/2/2010\" (23th Feb 2010). I want to pass it to a function which would return the day of week. How can I do this?

I

25条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-22 05:55

    Simply use SimpleDateFormat.

    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy", java.util.Locale.ENGLISH);
    Date myDate = sdf.parse("28/12/2013");
    sdf.applyPattern("EEE, d MMM yyyy");
    String sMyDate = sdf.format(myDate);
    

    The result is: Sat, 28 Dec 2013

    The default constructor is taking "the default" Locale, so be careful using it when you need a specific pattern.

    public SimpleDateFormat(String pattern) {
        this(pattern, Locale.getDefault(Locale.Category.FORMAT));
    }
    

提交回复
热议问题