Java生成時間戳

2021-07-08 17:20:30 字數 984 閱讀 3382

通常使用:system.currenttimemillis() – 1449565025434

但是會出現重複,同時間多次請求建議不使用這種方法

這種方法生成的是唯一的時間編碼 ,– 12081657054320000

/**時間格式生成唯一編碼start**/

/* the fieldposition. /

private static final fieldposition helper_position = new fieldposition(0);

/** this format for format the data to special format. */

private final static format dateformat = new ******dateformat("mmddhhmmsss");

/** this format for format the number to special format. */

private final static numberformat numberformat = new decimalformat("0000");

/** this int is the sequence number ,the default value is 0. */

private static int seq = 0;

private static final int max = 9999;

/** * 時間格式生成序列

* @return string

*/public static synchronized string generatesequenceno() else

return sb.tostring();

}/************ 時間格式生成唯一編碼end ************/

用做記錄

js生成時間戳

date 物件用於處理日期和時間。new date 生成時間戳 function createtimestamp 三種方法生成時間戳 第一種var timestamp1 date.parse new date 1372751992000 第一種獲取的時間戳是把毫秒改成000顯示 第二種 var ti...

Java計算時間戳差值

計算time2減去time1的差值 差值只設定 幾天 幾個小時 或 幾分鐘 根據差值返回多長之間前或多長時間後 public static string getdistancetime long time1,long time2 else day diff 24 60 60 1000 hour di...

Java獲得時間戳

今天做專案,有個需要獲得時間戳的字段。目前知道兩種方法可以獲得時間戳,也就是從格林威治時間1970年01月01日00時00分00秒 北京時間1970年01月01日08時00分00秒 起至現在的總秒數。一是date類的gettime方法。二是system的currenttimemillis方法。後者的...