我正在尝试使用
获取本周的当前日期<script type="text/javascript">
var now = new Date();
var today = now.getDay();
</script>
并希望在if-else条件下使用今天的日期。如何在scala中使用此var
答案 0 :(得分:0)
您可以使用Joda DateTime
val dateTime = new DateTime();
println("Day:" + dateTime.getDayOfWeek);
要将DateTime对象传递到模板,请写入模板文件的顶部;
@(datetime: DateTime)
有关ScalaTemplates的详细说明 - &gt; https://www.playframework.com/documentation/2.4.0/ScalaTemplates
您可以在模板文件中声明它;
@import org.joda.time.DateTime; val datetime = new DateTime();
答案 1 :(得分:0)
以下作品,
@import java.time.LocalDateTime
@main("Welcome to Play") {
<script type="text/javascript">
var date = "@Html(LocalDateTime.now().toString())";
console.log(date);
</script>
}