C# (Unity)で数字→month (月の略称)変換
数字→month (月の略称)変換のプログラムです。
備忘録です。雑ですが、お許しを...
month.cs
using System;
namespace date{
public class month
{
public static string monthName(int monthNumber)
{
if (monthNumber < 1 || monthNumber > 12)
{
return "Error. Please input number between 1 - 12";
}
var monthName = Enum.GetName(typeof(Month), monthNumber);
if (monthNumber < 5 || monthNumber > 7)
monthName += ".";
return monthName;
}
private enum Month
{
Jan = 1,
Feb = 2,
Mar = 3,
Apr = 4,
May = 5,
June = 6,
July = 7,
Aug = 8,
Sept = 9,
Oct = 10,
Nov = 11,
Dec = 12
}
}
}
使い方は下の感じ
int month = 8;
var text = date.month.monthName(month);
Debug.Log(text); // 出力 : Aug.
参考