在Java中可以使用System.currentTimeMillis()
方法来获取当前时间的毫秒数,然后可以将该毫秒数除以1000来获取当前秒数。
示例代码如下:
long currentTimeMillis = System.currentTimeMillis();
long currentSecond = currentTimeMillis / 1000;
System.out.println("Current second: " + currentSecond);
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:java如何获取当前时间精确到纳秒