java - 为什么使用 Java SimpleDateFormat 会减少一个月?

标签 java date formatting

我正在使用 SimpleDateFormat 来显示这样的日历:

public String getDate()
{
    String DATE_FORMAT = "EEEE, dd/MM/yyyy HH:mm:ss";
    SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
    System.err.println(date.getTime().getMonth());
    return sdf.format(date.getTime());
}

shell 返回 6 并显示:mardi, 06/07/2010 12:44:52

不可能吗?为什么?

谢谢

最佳答案

来自 Java API :

public int getMonth()

Returns a number representing the month that contains or begins with the instant in time represented by this Date object. The value returned is between 0 and 11, with the value 0 representing January.

关于java - 为什么使用 Java SimpleDateFormat 会减少一个月?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2992381/

相关文章:

java - fragment 着色器无效。链接无法继续

java - 并发 api 的 AbstractQueuedSynchronizer 构建 block 如何没有任何同步?

java - Android :Runtime exception 应用程序崩溃

c# - 使用日期(2015 年 9 月 11 日 --> 日期格式)按降序对 C# 列表进行排序?

Android - 如何添加日期

pandas - 使用 Python 中的 StyleFrame 库在 Excel 中显示尾随零时出现问题

mysql - 如何: Format a MySQL query result with currency signs using PHP

java - 将 Java 代码格式化为 Word/RTF

java - 使用Zoom API共享对Zoom Meeting设置的访问权限

python - 在 Python 中查找下一个最近的时间