Month name from integer
-
I don't really know if there is a built-in function (I looked in System.DateTime but didn't see one) so I threw this one together:
private string MonthName(int iMonth) { string[] sMonths = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; return sMonths[iMonth] ; }
thanks for that GISnet. I didn't see one either and wondered if I'd missed something really obvious and was being stoopid :wtf: It ain't what you know that matters. U.M.
-
I have an integer representing a month, what is the best way to convert it into the full month name? thanks U.M. It ain't what you know that matters. Uncle Monkey
System.Globalization.DateTimeFormatInfo.MonthNames
-
System.Globalization.DateTimeFormatInfo.MonthNames
-
I have an integer representing a month, what is the best way to convert it into the full month name? thanks U.M. It ain't what you know that matters. Uncle Monkey
Here is my contribution:
public enum Months
{
January = 1,
February,
March,
April,
May,
June,
July,
August,
September,
October,
November,
December
};[STAThread]
static void Main(string[] args)
{
for (Months month = Months.January; month <= Months.December; month++)
Console.WriteLine ("{0} - {1}", (int)month, month.ToString ());
}α.γεεκ
Fortune passes everywhere.
Duke Leto Atreides -
Here is my contribution:
public enum Months
{
January = 1,
February,
March,
April,
May,
June,
July,
August,
September,
October,
November,
December
};[STAThread]
static void Main(string[] args)
{
for (Months month = Months.January; month <= Months.December; month++)
Console.WriteLine ("{0} - {1}", (int)month, month.ToString ());
}α.γεεκ
Fortune passes everywhere.
Duke Leto AtreidesJim Stewart wrote: Here is my contribution: This has no international support... :(( ORACLE One Real A$#h%le Called Lary Ellison
-
Jim Stewart wrote: Here is my contribution: This has no international support... :(( ORACLE One Real A$#h%le Called Lary Ellison
I respectfully submit that the problem description did not indicate the need for internationalization. Therefore my modest contribution met the initial requirements.
Since the bar has been raised, I will attempt to satisfy.
One solution might go thus:public enum Mois
{
Janvier = 1,
Février,
Mars,
Avril,
Peut,
Juin,
Juillet,
Août,
Septembre,
Octobre,
Novembre,
Décembre
};
[STAThread]
static void Main(string[] args)
{
for (Mois mois = Mois.Janvier; mois <= Mois.Décembre; mois++)
{
Console.WriteLine (mois.ToString ());
}
}I suspect that this is not what was intended. So to blend my previous solution with Monsieur Nischalke:
public enum Months
{
January,
February,
March,
April,
May,
June,
July,
August,
September,
October,
November,
December
};
[STAThread]
static void Main(string[] args)
{
DateTimeFormatInfo dtfi = new DateTimeFormatInfo ();
for (Months month = Months.January; month <= Months.December; month++)
{
Console.WriteLine (dtfi.MonthNames[(int)month]);
}
}This has the benefit of symbolic constants instead of literals with the internationalization.
α.γεεκ
Fortune passes everywhere.
Duke Leto Atreides -
I respectfully submit that the problem description did not indicate the need for internationalization. Therefore my modest contribution met the initial requirements.
Since the bar has been raised, I will attempt to satisfy.
One solution might go thus:public enum Mois
{
Janvier = 1,
Février,
Mars,
Avril,
Peut,
Juin,
Juillet,
Août,
Septembre,
Octobre,
Novembre,
Décembre
};
[STAThread]
static void Main(string[] args)
{
for (Mois mois = Mois.Janvier; mois <= Mois.Décembre; mois++)
{
Console.WriteLine (mois.ToString ());
}
}I suspect that this is not what was intended. So to blend my previous solution with Monsieur Nischalke:
public enum Months
{
January,
February,
March,
April,
May,
June,
July,
August,
September,
October,
November,
December
};
[STAThread]
static void Main(string[] args)
{
DateTimeFormatInfo dtfi = new DateTimeFormatInfo ();
for (Months month = Months.January; month <= Months.December; month++)
{
Console.WriteLine (dtfi.MonthNames[(int)month]);
}
}This has the benefit of symbolic constants instead of literals with the internationalization.
α.γεεκ
Fortune passes everywhere.
Duke Leto AtreidesSince the gauntlet of challenge has been thrown.
using System.Globalization; CultureInfo ci = new CultureInfo("fr-FR", true); DateTimeFormatInfo di = ci.DateTimeFormat; foreach(string strMonth in di.MonthNames) Console.WriteLine(strMonth);
-
Since the gauntlet of challenge has been thrown.
using System.Globalization; CultureInfo ci = new CultureInfo("fr-FR", true); DateTimeFormatInfo di = ci.DateTimeFormat; foreach(string strMonth in di.MonthNames) Console.WriteLine(strMonth);
May I ask how one gets the month name from an integer in this scenario?
α.γεεκ
Fortune passes everywhere.
Duke Leto Atreides -
May I ask how one gets the month name from an integer in this scenario?
α.γεεκ
Fortune passes everywhere.
Duke Leto AtreidesDateTimeFormatInfo.MonthNames Gets or sets a one-dimensional array of type String containing the culture-specific full names of the months.
-
DateTimeFormatInfo.MonthNames Gets or sets a one-dimensional array of type String containing the culture-specific full names of the months.
Touche - I was getting a bit punchy last night.
α.γεεκ
Fortune passes everywhere.
Duke Leto Atreides