55
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

posted at

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

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);

    }

}
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
55
Help us understand the problem. What are the problem?