gpt4 book ai didi

variables - DateUtil.AddDays是否接受#天的变量?

转载 作者:行者123 更新时间:2023-12-02 10:42:57 25 4
gpt4 key购买 nike

我试图在调用DateUtil.addDays的天数中使用一个变量,但是它不起作用。我是否缺少一些简单的东西,或者只是行不通?

//Example:
x = 10 //this int is the result of some math, and changes frequently
y = Thu Aug 31 00:00:00 MST 2017 //this is the date

z = DateUtil.addDays(y, x) //This will error.
z = DateUtil.addDays(y, 10) //This works.

最佳答案

您必须谨慎使用Java类型。

例子 :

// suppose variable y contains your date as in your example
int x = 10; // value is 10
double w = x; // value is same as 10 (or, more precisely, 10.0)

z = DateUtil.addDays(y, x); // This will compile.

// This will not compile. AddDays expect an argument of type `int`,
// not a `double`, even if the value inside is mathematically
// the same as the int 10.
z = DateUtil.addDays(y, w);

// This will compile : the result of Math.round() is of type int
z = DateUtil.addDays(y, Math.round(w));

关于variables - DateUtil.AddDays是否接受#天的变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45991181/

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