Java obtains the current time
1. Use the Calendar in Java to obtain the current time
The specific implementation is as follows:
/*** @ Title: NowTime. java * @ Package: com. you. model * @ Description: Get the current time * @ Author: youhaidong * @ date: 10:38:20, January 1, April 4, 2014 * @ Version V1.2.3 */package com. you. model; import java. util. calendar;/*** @ Class Name: NowTime * @ Description: * @ Author: youhaidong * @ date: april 4, 2014 10:38:20 */public class NowTime {/***** @ Title: findTime * @ Type: NowTime * @ date: April 4, 2014 10:44:35 * @ Description: obtain the current system time * @ return */public s Tatic String findTime () {Calendar calendar = Calendar ar. getInstance ();/*** hour */int hour = calendar. get (Calendar. HOUR);/*** minute */int minute = calendar. get (Calendar. MINUTE);/*** seconds */int second = calendar. get (Calendar. SECOND);/*** splicing time (hour, minute, and SECOND) */String time = (hour <10? "0" + hour: hour) + ":" + (minute <10? "0" + minute: minute) + ":" + (second <10? "0" + second: second);/*** returns the hour, minute, and second */return time;}/*** @ Title: main * @ Type: NowTime * @ date: april 4, 2014 10:38:20 * @ Description: Test findTime () * @ param args */public static void main (String [] args) {/*** call the findTime Method */String nowsday = findTime ();/*** print the result */System. out. println ("current time:" + nowsday );}}
2. Implementation result
Current Time: 10: 53: 04