java - 使用 LocalDate 存储日期

标签 java date

我正在尝试将以前的日期存储在 LocalDate 对象中,但我不确定如何存储。 到目前为止,我一直在使用自己的类,但我想应用 java.time.LocalDate 库。 帮忙?

我的代码: LocalDate theDate = new LocalDate(theYear, theMonth, theDay);

错误信息: LocalDate theDate = new LocalDate(theYear, theMonth, theDay);

最佳答案

像这样尝试:

Java 8 java.time.LocalDate类没有公共(public)构造函数,

public class test {
    public static void main(String[] args) {
        int theYear=2016;
        int theMonth=1;
        int theDay=21;
        LocalDate theDate = LocalDate.of(theYear,theMonth,theDay);
        System.out.println(theDate);
    }



}

关于java - 使用 LocalDate 存储日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34917851/

相关文章:

MySQL : first day of the week and last day of the week not working as desired

java - 在 Java 中获取准确的日期而不干扰 XMLGregorianCalendar

java - Jersey 2.x 安全上下文不起作用?

java - WstxUnexpectedCharException : Unexpected character '"' (code 34) in DOCTYPE declaration; expected a space between public and system identifiers

java - 在 Java 中存储颜色 - byte;byte;byte vs. byte[3] vs int

java - 通过SimpleDateFormat解析系统时间报错

java - 不同的 SimpleDateFormat 解析

php - 以特定格式在 PHP 中为 1970 年之前的日期创建日期对象

java - 无法从java中的另一个类调用方法

java - 关闭 CloseableHttpResponse/CloseableHttpClient 的正确方法