DateManager.csUnity記事: 目次
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
using System; using UnityEngine; /// <summary> /// /// Unity 2018.2.10f1 /// /// </summary> public class DateManager : MonoBehaviour { // Use this for initialization private void Start() { string youbi = GetDayOfTheWeek("20180401"); Debug.Log(youbi); } // 日付から曜日を取得する private string GetDayOfTheWeek(string date) { // DateTimeを生成 DateTime dateTime = DateTime.ParseExact(date, "yyyyMMdd", null); // 日本語の曜日を取得 string dayOfWeekJa = ""; switch (dateTime.DayOfWeek) { case DayOfWeek.Sunday: dayOfWeekJa = "(日)"; break; case DayOfWeek.Monday: dayOfWeekJa = "(月)"; break; case DayOfWeek.Tuesday: dayOfWeekJa = "(火)"; break; case DayOfWeek.Wednesday: dayOfWeekJa = "(水)"; break; case DayOfWeek.Thursday: dayOfWeekJa = "(木)"; break; case DayOfWeek.Friday: dayOfWeekJa = "(金)"; break; case DayOfWeek.Saturday: dayOfWeekJa = "(土)"; break; } // 曜日 (英語) Debug.Log(dateTime.ToString("dddd")); Debug.Log(dateTime.ToString("ddd")); // 戻り値: 曜日 (日本語) return dayOfWeekJa; } } |