動作確認
Unity 5.1.3-f1 on MacOS X 10.8.5
現在時刻が前の日曜日から何日目かを知りたい。
MyScript.cs
using UnityEngine;
using System.Collections;
using System; // for TimeSpan
/*
* v0.1 2015/09/12
* - get days from sunday
*/
public class MyScript : MonoBehaviour {
System.DateTime getSundayH00M00S00(System.DateTime dt) {
System.DateTime res = dt;
dt -= new TimeSpan ((int)dt.DayOfWeek, dt.Hour, dt.Minute, dt.Second);
return dt;
}
void Test_weekly() {
System.DateTime now = System.DateTime.Now;
System.DateTime sunday = getSundayH00M00S00 (now);
int daysdiff = now.Subtract (sunday).Days;
Debug.Log ("now: " + now.ToString ());
Debug.Log ("sunday: " + sunday.ToString ());
Debug.Log ("days: " + daysdiff);
}
void Start () {
Test_weekly ();
}
}
きちんと6日が取得できた。