gpt4 book ai didi

java - 如何在 Java 中按日期推断信息

转载 作者:行者123 更新时间:2023-12-01 17:03:09 25 4
gpt4 key购买 nike

我有以下格式的对象日期:2014-05-20 18:17:26.337

我尝试这样做:

Calendar c = Calendar.getInstance();
c.setTime(myDate);
int dayOfWeek = c.get(Calendar.DAY_OF_WEEK);
int dayOfMonth = c.get(Calendar.DAY_OF_MONTH);
int Month = c.get(Calendar.MONTH);
int year = c.get(Calendar.YEAR);

但是信息是错误的..

如何解决?

最佳答案

这是期望值,请仔细阅读javadoc: http://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html#MONTH

月份:

Field number for get and set indicating the month. This is a calendar-specific value. The first month of the year in the Gregorian and Julian calendars is JANUARY which is 0; the last depends on the number of months in a year.

对于星期几:

public static final int DAY_OF_WEEK Field number for get and set indicating the day of the week. This field takes values SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, and SATURDAY.

关于java - 如何在 Java 中按日期推断信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26670997/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com