Getting “unixtime” in Java
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Date.getTime() returns milliseconds since Jan 1, 1970. Unixtime is seconds since Jan 1, 1970. I don't usually code in java, but I'm working on some bug fixes. I have: Date now = new Date(); Long longTime = new Long(now.getTime()/1000); return longTime.intValue(); Is there a better way to get unixtime in java? UPDATE Based on John M's suggestion, I ended up with: return (int) (System.currentTimeMillis() / 1000L); 回答1: Avoid the Date object creation w/ System.currentTimeMillis() . A divide by 1000 gets you to Unix epoch. As mentioned in a