如何使用播放框架和 Scala 获取系统时间?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16771299/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to get System time using play framework and scala?
提问by 4lex1v
how to get System time using play framework and scala ?
如何使用播放框架和 Scala 获取系统时间?
Using playframework2.0 and scala get the system time to web program is there is any different ways...
使用 playframework2.0 和 scala 获取系统时间到 web 程序是否有任何不同的方法...
回答by 4lex1v
if you want to paste System time into your Twirl html template, simply add @symbol before System
如果要将系统时间粘贴到 Twirl html 模板中,只需@在 System 之前添加符号
@System.currentTimeMillis
or
或者
@System.nanoTime
Update
更新
If u need some format for current time in play then add some helper method in your Twirl template like this:
如果你需要一些当前播放时间的格式,那么在你的 Twirl 模板中添加一些辅助方法,如下所示:
@currentTime = @{
import java.util.Calendar
import java.text.SimpleDateFormat
val today = Calendar.getInstance.getTime
val curTimeFormat = new SimpleDateFormat("HH:mm")
curTimeFormat.format(today)
}
then simple call this method in your template:
然后在你的模板中简单地调用这个方法:
<div>@currentTime</div>
You can read about Twirld template engine here: Scala Templateand about format rules here: SimpleDateFormat
您可以在此处阅读有关 Twirld 模板引擎的信息:Scala 模板和此处的格式规则:SimpleDateFormat
回答by Ivan Meredith
Try System.currentTimeMillis?
试试System.currentTimeMillis?
回答by riko noc
Use this:
用这个:
val today = Calendar.getInstance().getTime()

