亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何檢查給定的字符串轉換為 long 是否是 EpochMills?

如何檢查給定的字符串轉換為 long 是否是 EpochMills?

Helenr 2023-05-10 14:25:01
您好有什么方法可以檢查給定的字符串是否是 epoch millisjava.time 包中的以下代碼轉換為 EpochMillis。我正在尋找 isEpochMillis 以返回布爾條件。是否有來自 apache commons 或 google guava 的現成的 api 來檢查這個?就像 isDouble isLong 等.../**     * Obtains an instance of {@code Instant} using milliseconds from the     * epoch of 1970-01-01T00:00:00Z.     * <p>     * The seconds and nanoseconds are extracted from the specified milliseconds.     *     * @param epochMilli  the number of milliseconds from 1970-01-01T00:00:00Z     * @return an instant, not null     * @throws DateTimeException if the instant exceeds the maximum or minimum instant     */    public static Instant ofEpochMilli(long epochMilli) {        long secs = Math.floorDiv(epochMilli, 1000);        int mos = (int)Math.floorMod(epochMilli, 1000);        return create(secs, mos * 1000_000);    }
查看完整描述

3 回答

?
有只小跳蛙

TA貢獻1824條經驗 獲得超8個贊

任何正整數在理論上都是有效的。您可以根據自己對領域的了解添加約束。例如:未來沒有時間戳,因此所有大于 Instant.now().toEpochMillis() 的數字都是無效的。



查看完整回答
反對 回復 2023-05-10
?
慕田峪4524236

TA貢獻1875條經驗 獲得超5個贊

沒有,但這是該方法的實現:

public static boolean isEpochMillis(long epochMilli) { 
  return true; 
}

當然,既然您看到了它的實現,您可能會發現這個方法是不必要的。


查看完整回答
反對 回復 2023-05-10
?
繁花不似錦

TA貢獻1851條經驗 獲得超4個贊

epochMilli 是自 1970-01-01 以來的毫秒數。所有長值都是有效的 epochMillis。歸結為您允許的日期。那將是你的范圍。

-2 將導致1969-12-31T23:59:59.998?Z。


查看完整回答
反對 回復 2023-05-10
  • 3 回答
  • 0 關注
  • 231 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號