close
程式目標: 抓取電腦當下的時間
程式碼如下:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.text.SimpleDateFormat; | |
import java.util.Date; | |
public class Test { | |
public static void main(String args[]){ | |
SimpleDateFormat sdFormat = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss"); | |
Date date = new Date(); | |
String strDate = sdFormat.format(date); | |
System.out.println(strDate); | |
} | |
} |
特別注意到,程式碼的 Line 6 hh 代表的是12小時制的時間,舉例來說: 2017/09/05 03:45:39。
如果把 hh 改成 HH,就會變成 24小時制的時間,像是: 2017/09/05 15:45:39
全站熱搜