如何在Dart中获取时间戳? [英] How to get a timestamp in Dart?
本文介绍了如何在Dart中获取时间戳?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在学习Dart,但是我不知道如何生成时间戳。我已经尝试过:
I've been learning Dart, but I don't know how to generate a timestamp. I have tried this:
void main() {
print((new Date()).millisecondsSinceEpoch);
}
多亏了IDE,我才能够做到这一点,但是
我收到一个令人困惑的错误:
Thanks to the IDE I was able to get this far, but I'm getting a confusing error:
Exception: No such method: 'Date'
帮助?
推荐答案
您几乎做对了。您只是没有使用命名构造函数:
You almost had it right. You just did not use a named constructor:
void main() {
print(DateTime.now().millisecondsSinceEpoch);
}
礼物:
1351441456747
1351441456747
有关更多信息,请参见API文档: https://api.dart.dev/stable/2.10.1/dart-core/DateTime-class.html
See the API documentation for more: https://api.dart.dev/stable/2.10.1/dart-core/DateTime-class.html
这篇关于如何在Dart中获取时间戳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文