/** * 获取时间戳 * * @param dateCur * @return */ public static long GetTicks(String dateCur) { // convert the target-epoch time to a well-format string // String date = new java.text.SimpleDateFormat("yyyy/MM/dd/HH/mm/ss") // .format(new Date(Long.parseLong(epochStr))); // SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd/HH/mm/ss"); // String dateCur = sdf.format(new Date()); String[] ds = dateCur.split("/");
// start of the ticks time Calendar calStart = Calendar.getInstance(); /** * 此处的参数很重要,原则上都是1,日所以为2,是因为之前的日期没减掉1 第三个参数为1:日期多了2天,为2则日期多1天 * **/ //上传失败时这里总会出现混乱的情况,需要找到源头解决 // calStart.set(1, 1, 0, 0, 0, 0); calStart.set(1, 1, 3, 0, 0, 0);
// the target time Calendar calEnd = Calendar.getInstance(); calEnd.set(Integer.parseInt(ds[0]), Integer.parseInt(ds[1]), Integer.parseInt(ds[2]), Integer.parseInt(ds[3]), Integer.parseInt(ds[4]), Integer.parseInt(ds[5]));
// epoch time of the ticks-start time long epochStart = calStart.getTime().getTime(); // epoch time of the target time long epochEnd = calEnd.getTime().getTime();
// get the sum of epoch time, from the target time to the ticks-start // time long all = epochEnd - epochStart; // convert epoch time to ticks time long ticks = ((all / 1000) * 1000000) * 10;
return ticks; } |