System.currentTimeMillis()获取前一天
时间: 2023-11-15 22:16:02 浏览: 307
通过System.currentTimeMillis()方法获取的时间戳是当前时间的毫秒数,它表示从1970年1月1日00:00:00 GMT(格林尼治标准时间)到当前时间的毫秒数。要获取前一天的时间戳,我们可以先获取当前时间戳,然后减去一天的毫秒数。一天的毫秒数等于24小时乘以60分钟乘以60秒乘以1000毫秒,即24 * 60 * 60 * 1000。代码如下:
long currentTimeMillis = System.currentTimeMillis();
long oneDayInMillis = 24 * 60 * 60 * 1000; // 一天的毫秒数
long previousDayInMillis = currentTimeMillis - oneDayInMillis;
这样,previousDayInMillis就是获取到的前一天的时间戳。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [Java进阶(十六)使用new Date()和System.currentTimeMillis()获取当前时间戳](https://blog.csdn.net/m0_67401920/article/details/126107871)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *3* [java 获取指定日期(带毫秒)13位时间戳](https://download.csdn.net/download/ava20_06/11002545)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文