在Java中,可以使用System.currentTimeMillis()方法来获取当前时间的时间戳(即从1970年1月1日00:00:00 UTC到现在的毫秒数)。要将时间戳转换为Date对象,可以使用new Date(timestamp)构造方法,其中timestamp是时间戳的值。
另外,要将Date对象转换为时间戳,可以使用getTime()方法,该方法返回自1970年1月1日00:00:00 UTC以来的毫秒数。例如:
long timestamp = System.currentTimeMillis();
Date date = new Date(timestamp);
long newTimestamp = date.getTime();