Warning: include_once(): http:// wrapper is disabled in the server configuration by allow_url_include=0 in /home/users/2/moriya-h5/web/confrage/java/date/date/date.html on line 2

Warning: include_once(http://www.confrage.com/bin/header.php): failed to open stream: no suitable wrapper could be found in /home/users/2/moriya-h5/web/confrage/java/date/date/date.html on line 2

Warning: include_once(): Failed opening 'http://www.confrage.com/bin/header.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/java/date/date/date.html on line 2
Calendar型で日付書式 | Java | 株式会社CONFRAGE
Warning: include_once(/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/menu.php): failed to open stream: No such file or directory in /home/users/2/moriya-h5/web/confrage/java/date/date/date.html on line 17

Warning: include_once(): Failed opening '/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/menu.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/java/date/date/date.html on line 17
Calendar型で日付書式
Javaでは日付書式が色々指定することが出来ます。
Calendarクラスで時間を取得して、SimpleDateFormatクラスで書式を指定することが出来ます。

SimpleDateFormatのコンストラクタの第一引数にString型でフォーマットを指定します。

サンプル
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class sysdt {

    public static void main(String[] args) {
        // パターン文字
        String format[] = {
                "yyyyMMdd",
                "yyyy/MM/dd",
                "w",// 
                "W",// 
                "d",// 
                "D",// 
                "G",// 西暦
                "F",// 第何月曜日か
                "E",// 曜日
                "a",// 午前 or 午後
                "yyyy年MM月dd日 KK:mm:ss SSS",
                "yyyy/MM/dd HH:mm:ss SSS",
                "yyyy/MM/dd kk:mm:ss SSS",
                "yyyy/MM/dd hh:mm:ss SSS",
                "yyyy/MM/dd ak:mm:ss SSS",
                "yyyy/MM/dd ah:mm:ss SSS",
                "yyyy/MM/dd K:m:s SSS",
                "yyyy/MM/dd H:m:s SSS"
        }; 
        
	for(int i = 0;i<format.length ;i++){
            Calendar calendar = Calendar.getInstance();   
            System.out.println(
             new SimpleDateFormat(format[i]).format(calendar.getTime()));
        }
    }
}
実行結果は以下のようになります。

20070126
2007/01/26
4
4
26
26
西暦
4
金
午後
2007年01月26日 07:07:00 265
2007/01/26 19:07:00 265
2007/01/26 19:07:00 265
2007/01/26 07:07:00 265
2007/01/26 午後19:07:00 265
2007/01/26 午後7:07:00 281
2007/01/26 7:7:0 281
2007/01/26 19:7:0 281

Back to top

Information

Warning: include_once(/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/side_bar.php): failed to open stream: No such file or directory in /home/users/2/moriya-h5/web/confrage/java/date/date/date.html on line 124

Warning: include_once(): Failed opening '/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/side_bar.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/java/date/date/date.html on line 124

Warning: include_once(/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/seo.php): failed to open stream: No such file or directory in /home/users/2/moriya-h5/web/confrage/java/date/date/date.html on line 133

Warning: include_once(): Failed opening '/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/seo.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/java/date/date/date.html on line 133