LoginSignup
0
0

More than 5 years have passed since last update.

unity > System.DateTime > "09/10 13:30"をパース > FormatException: String was not recognized as a valid DateTime. > 2015/09/10 13:30でないとだめ

Last updated at Posted at 2015-09-12
動作確認
Unity 5.1.2-f3 on MacOS X 10.8.5

横軸が1週間のグラフの実装をしていて、日付のパースに失敗した。

09/10 13:30という日時を読み取ろうとして

System.DateTime dt = System.DateTime.Parse ("09/10 13:30");
Debug.Log (dt.ToString ());

したら、以下のエラーとなった。

FormatException: String was not recognized as a valid DateTime.

以下の結果であった。

  • 2015/09/10 13:30 : OK
  • 15/09/10 13:30 : NG
  • 09/10 13:30 : NG

後者2つがダメな理由としてはどれがmonth, dayなのか判別できないからなのだろう。

ただし、2015/09/10がyyyy/mm/ddの場合とyyyy/dd/mmの場合もあり、このあたりはyyyy/mm/dd固定なのだろう。

0
0
0

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
0
0