The pit of long integer conversion to date

  At work, in joint debugging with a third party, the date of the other party is a long integer number stored in the varchar type in order to save the storage space of the database. It turned out to be 2017 in the conversion showcase.

  After communication, it turns out that the other party stores the Unix timestamp (Unix timestamp), which needs to be multiplied by 1000 to convert it into milliseconds. Examples are as follows:

package com.bijian.test;

public class DateTest {

	public static void main(String[] args) {
		
		long p = 1514447530l;
		String date = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new java.util.Date(p));
		System.out.println(date); //1970-01-18 20:40:47
		
		String date2 = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new java.util.Date(p * 1000));
		System.out.println(date2); //2017-12-28 15:52:10
		
		System.out.println(System.currentTimeMillis()); //1515936461590
	}
}

 

Reference: http://tool.chinaz.com/Tools/unixtime.aspx

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326434443&siteId=291194637