如何获取一周中的当前日期并在Play框架中的scala模板中使用它

时间:2015-11-03 11:58:43

标签: scala playframework

我正在尝试使用

获取本周的当前日期
<script type="text/javascript">
        var now = new Date();
        var today = now.getDay();

        </script>

并希望在if-else条件下使用今天的日期。如何在scala中使用此var

2 个答案:

答案 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>

}