javascript 中的var now = new Date()语句在Java中如何实现?

2025年01月07日 08:19
有5个网友回答
网友(1):

js中var now = new Date();是获取当前时间的意思

翻译成java就是

  Date now = new Date();

 等同于js的var now = new Date();

网友(2):

int hour = java.util.Calendar.HOUR;
String greet ="Good" + ( hour > 18 ? " evening." : " day.");

网友(3):

Date now = new Date();
String greeting = "Good" + ((now.getHours()>18)?"evening." : "day.");
System.out.print(greeting);

网友(4):

Date now= new Date();
String greeting = "Good";
if(now.getHours()>18)
{
greating = "Good evening";
}
else
{
greating = "Good day ";
}

网友(5):

Date now = new Date();