The following example demonstrates how to use the format(date) method of the Date class and SimpleDateFormat class to output the current time:
/* author by w3cschool.cc 文件名:Main.java */import java.text.SimpleDateFormat;import java.util.Date;public class Main{ public static void main(String[] args){ SimpleDateFormat sdf = new SimpleDateFormat();// 格式化时间 sdf.applyPattern("yyyy-MM-dd HH:mm:ss a");// a为am/pm的标记 Date date = new Date();// 获取当前时间 System.out.println("现在时间:" + sdf.format(date)); // 输出已经格式化的现在时间(24小时制) } }
The output result of the above code is:
现在时间:2015-03-27 21:27:28 下午
The above is the Java example - getting the content of the current time. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!