LoginSignup
54
54

More than 5 years have passed since last update.

文字列日付からDate型への変換

Posted at

Javaで文字列で渡された日付形式をDate型に変換する。

Webシステムにおいて、入力値にある日付の妥当性チェック等を行う
時に使う際のメモ。

ConvertDateFromString
public class ConvertDateFromString {

    public static void main(String[] args) throws ParseException {

        // 変換対象の日付文字列
        String dateStr = "20140101 00:00:00";

        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd HH:mm:ss");

        // Date型変換
        Date formatDate = sdf.parse(dateStr);

    }

}
54
54
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
54
54