In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
The example analysis of the conversion between System.currentTimeMillis () calculation method and time unit in Java, aiming at this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
I. conversion of units of time
1 second = 1000 milliseconds (ms) 1 millisecond = 1 stroke 1000 seconds (s)
1 second = 1000000 microseconds (μ s) 1 microseconds = 1 million seconds (s)
1 second = 1000000000 nanoseconds (ns) 1 nanosecond = 1 pound 1000000000 seconds (s)
1 second = 1000000000000 picoseconds (ps) 1 picosecond = 1Universe 1000000000000 seconds (s)
1 minute = 60 seconds
1 hour = 60 minutes = 3600 seconds
II. System.currentTimeMillis () calculation method
During the development process, many people are used to using new Date () to get the current time. What new Date () does is actually call System.currentTimeMillis (). If it is only required or milliseconds, then you can use System.currentTimeMillis () instead of new Date (), which is a little more efficient. If you need to use new Date () multiple times in the same method, the performance is usually consumed bit by bit, and you can actually declare a reference here.
/ / the time to get the system, in milliseconds, converted to wonderful long totalMilliSeconds = System.currentTimeMillis (); long totalSeconds = totalMilliSeconds / 1000; / / the second long currentSecond = totalSeconds% 60; / / the score long totalMinutes = totalSeconds / 60; long currentMinute = totalMinutes% 60 / / long totalHour = totalMinutes / 60; long currentHour = totalHour% 24; / / display time System.out.println ("total milliseconds:" + totalMilliSeconds); System.out.println (currentHour + ":" + currentMinute + ":" + currentSecond + "GMT"); small example: package demo.spli;import java.text.DateFormat;import java.text.SimpleDateFormat Import java.util.Date;import java.util.TimeZone;public class ShowCurrentTime {/ * @ shows the current time * @ 2014.9.3 * / public static void main (String [] args) {/ / TODO Auto-generated method stub / / the time to acquire the system, in milliseconds, converted to wonderful long totalMilliSeconds = System.currentTimeMillis () DateFormat dateFormatterChina = DateFormat.getDateTimeInstance (DateFormat.MEDIUM,DateFormat.MEDIUM); / / formatted output TimeZone timeZoneChina = TimeZone.getTimeZone ("Asia/Shanghai"); / / get the time zone, which is critical. DateFormatterChina.setTimeZone (timeZoneChina); / / set the system time zone long totalSeconds = totalMilliSeconds / 1000; / / the second long currentSecond = totalSeconds% 60; / / the minute long totalMinutes = totalSeconds / 60; long currentMinute = totalMinutes% 60; / / the hour long totalHour = totalMinutes / 60; long currentHour = totalHour% 24 / / display time System.out.println ("total milliseconds:" + totalMilliSeconds); System.out.println (currentHour + ":" + currentMinute + ":" + currentSecond + "GMT"); Date nowTime = new Date (System.currentTimeMillis ()); System.out.println (System.currentTimeMillis ()); SimpleDateFormat sdFormatter = new SimpleDateFormat ("yyyy-MM-dd HH:mm:dd") String retStrFormatNowDate = sdFormatter.format (nowTime); System.out.println (retStrFormatNowDate);}}
System.currentTimeMillis () + 3600 to 1000) can be interpreted like this: System.currentTimeMillis () is equivalent to milliseconds, but after that it becomes 1000, which becomes seconds. So, 3600 seconds = 1 hour, so the output is 1 hour after the current time.
We can control the time like this: System.currentTimeMillis () + time*1000). The time passed in is in seconds. When 60 is passed in, the output: one minute after the current time.
This is the answer to the sample analysis question about the conversion of System.currentTimeMillis () calculation method and time unit in Java. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.