2018年03月31日

Eclipse ソースコードの整形ルールの設定

ソースコードの整形ルールの設定
Eclipse→ウィンドウ→設定→Java→コードスタイル→フォーマッター→編集

自動適用の設定
Eclipse→ウィンドウ→設定→Java→エディター→保管アクション
タグ:JAVA Eclipse
posted by Hiro at 11:42| Comment(0) | プログラム

2018年03月23日

Java 日付から文字列、文字列から日付へ変換

定番ですが、Javaで日付と文字列の相互変換のメモです。
LocalDateTime型とDate型の2パターンです。
import java.text.SimpleDateFormat;
import java.time.DateTimeException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

public class MyClass {

    private static String DATETIME_FORMAT = "yyyy年MM月dd日 HH時mm分ss秒";

    public static void main(String... arg) {

        // LocalDateTime型の変換
        System.out.println(dateTimeToString(LocalDateTime.now()));
        System.out.println(parseDateTime("2018年03月23日 20時34分45秒"));

        // Date型の変換
        System.out.println(dateToString(new Date()));
        System.out.println(parseDate("2018年03月23日 20時34分45秒"));
    }

    /**
     * LocalDateTime型を文字列へ変換
     * @param datetime 日付時刻
     * @return 日付時刻から変換した文字列
     */
    public static String dateTimeToString(LocalDateTime datetime) {
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern(DATETIME_FORMAT);
        return dtf.format(datetime);
    }

    /**
     * 文字列をLocalDateTime型へ変換
     * @param str 文字列
     * @return 文字列から変換した日付時刻
     */
    public static LocalDateTime parseDateTime(String str) {
        LocalDateTime ldt = null;
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern(DATETIME_FORMAT);
        try {
            ldt = LocalDateTime.parse(str, dtf);
        } catch (DateTimeException e) {
            // Date型に変換できないものはnull
            return null;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ldt;
    }

    /**
     * Date型を文字列へ変換
     * @param date 日付時刻
     * @return 日付時刻から変換した文字列
     */
    public static String dateToString(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat(DATETIME_FORMAT);
        return sdf.format(date);
    }

    /**
     * 文字列をDate型へ変換
     * @param str 文字列
     * @return 文字列から変換した日付時刻
     */
    public static Date parseDate(String str) {
        Date date = null;
        SimpleDateFormat sdf = new SimpleDateFormat(DATETIME_FORMAT);
        try {
            date = sdf.parse(str);
        } catch (java.text.ParseException e) {
            // Date型に変換できないものはnull
            return null;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return date;
    }
}
タグ:JAVA
posted by Hiro at 20:35| Comment(0) | プログラム

2018年03月19日

システム開発に関するサイトリンク

情報処理推進機構(IPA)
機能要件の合意形成ガイド
https://www.ipa.go.jp/sec/softwareengineering/reports/20100331.html
「機能要件の合意形成ガイド」の説明資料
https://www.ipa.go.jp/sec/softwareengineering/reports/20110603.html

総務省 業務・システム最適化の推進
http://www.soumu.go.jp/main_sosiki/gyoukan/kanri/a_01-02.html

総務省自治行政局自治政策課 自治体EA 業務システム刷新化の手引き
> IV.資料編1 表記方法 > 個別課題の解決方策の様式 > 業務流れ図(WFA)
http://www.soumu.go.jp/denshijiti/system_tebiki/hyouki/kadai/4-1-wfa.html
タグ:リンク
posted by Hiro at 21:29| Comment(0) | プログラム