The UNIX timestamp is the number of seconds that have elapsed since the start of the January 1, 1970 (Midnight of Utc/gmt), regardless of the leap seconds.
In most Unix systems, the UNIX timestamp is stored as 32 bits, which raises the 2038 issue.
However, because the requirement is a UNIX timestamp that requires an int type. That's how I designed it at first.
/** * Gets the current event unxi timestamp * @return */public static int Getunixtimestamp () {long Rest=system.currenttimemillis ()/1000l;return ( int) rest;}
New encapsulation of some methods. The following stability is much better.
1 Packagecom.xuanyuan.utils;2 3 Public classTimeutils {4 5 /**6 * Constant that contains the amount of milliseconds in a second7 */8 Static Final LongOne_second = 1000L;9 Ten /** One * Converts milliseconds to seconds A * @paramTimeinmillis - * @returnThe equivalent time in seconds - */ the Public Static intTosecs (LongTimeinmillis) { - //rounding the result to the ceiling, otherwise a - //System.currenttimeinmillis that happens right before a new Element - //instantiation'll be seen as ' later ' than the actual creation time + return(int) Math.ceil (Double) Timeinmillis/one_second); - } + A /** at * Converts seconds to milliseconds, with a precision of 1 second - * @paramTimeinsecs the time in seconds - * @returnThe equivalent time in milliseconds - */ - Public Static LongTomillis (inttimeinsecs) { - returnTimeinsecs *One_second; in } - to /** + * Converts a long seconds value to an int seconds value and takes into account overflow - * from the downcast by switching to Integer.max_value. the * @paramseconds Long Value * * @returnsame int value unless long > integer.max_value in which case Max_value is returned $ */Panax Notoginseng Public Static intConverttimetoint (Longseconds) { - if(Seconds >integer.max_value) { the returnInteger.max_value; +}Else { A return(int) seconds; the } + } - $}
Java Get UNIX Timestamp