本文整理汇总了C#中System.Globalization.DateTimeFormatInfo.GetMonthName方法的典型用法代码示例。如果您正苦于以下问题:C# DateTimeFormatInfo.GetMonthName方法的具体用法?C# DateTimeFormatInfo.GetMonthName怎么用?C# DateTimeFormatInfo.GetMonthName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Globalization.DateTimeFormatInfo
的用法示例。
在下文中一共展示了DateTimeFormatInfo.GetMonthName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Analysbtn_Click
private void Analysbtn_Click(object sender, EventArgs e)
{
//we check the input number and if the number length = 14 will move to next step
if (IDTB.Text.Length == 14)
{
//create object from DTFI to get month name
DateTimeFormatInfo dtfi = new DateTimeFormatInfo();
//create object from IDAnalyst which contains all of process
IDAnalyst id = new IDAnalyst();
//convert id number from string in textBox to long
long num = long.Parse(IDTB.Text);
//set DateTimePicker "Date" to Date input to extract name of the day and month
DTP.Value = new DateTime(int.Parse(id.GetBirthYear(num)), int.Parse(id.GetBirthMonth(num)), int.Parse(id.GetBirthDay(num)));
//assign value of Day TextBox to day from IDAnalyst class and get a day from DateTimePicker
Daytb.Text = id.GetBirthDay(num)+" : "+DTP.Value.DayOfWeek.ToString();
//Get Month and using DTFI to get month name which we get from DateTimePicker
Montb.Text = id.GetBirthMonth(num)+" : "+dtfi.GetMonthName(DTP.Value.Month);
//Get Month Year
Yeartb.Text = id.GetBirthYear(num);
//Get Sex
Sextb.Text = id.Sex(num);
//Get Get Province Name
provtb.Text = id.GetProvince(num);
//Get Child number
cid.Text = id.NumOfChild(num).ToString();
}
}
示例2: LoadPDF
private void LoadPDF()
{
/*
* ContractNumber1
ContractNumber2
SumOfMoneyPerTon
CropYear1
WithdrawalDate
CurrentDayMonth
Shareholder Signature
PrintLandOwnerName
PrintShareholderName
ShareholderAddress
Director WSCPAC
Company Representative
CurrentTwoDigitYear
*/
var pdfReader = new PdfReader(System.Web.HttpContext.Current.Server.MapPath("~/PDF/2015.pdf"));
var output = new MemoryStream();
var stamper = new PdfStamper(pdfReader, output);
var date = DateTime.Now;
DateTimeFormatInfo mfi = new DateTimeFormatInfo();
string strMonthName = mfi.GetMonthName(date.Month).ToString();
stamper.AcroFields.SetField("ContractNumber1", "");
stamper.AcroFields.SetField("ContractNumber2", "");
stamper.AcroFields.SetField("SumOfMoneyPerTon", "");
stamper.AcroFields.SetField("CropYear1", "");
stamper.AcroFields.SetField("WithdrawalDate", "");
stamper.AcroFields.SetField("CurrentDayMonth", mfi.GetMonthName(date.Month).ToString() + " " + date.Day);
stamper.AcroFields.SetField("Shareholder Signature", "");
stamper.AcroFields.SetField("PrintLandOwnerName", "");
stamper.AcroFields.SetField("PrintShareholderName", "");
stamper.AcroFields.SetField("ShareholderAddress", "");
stamper.AcroFields.SetField("Director WSCPAC", "");
stamper.AcroFields.SetField("Company Representative", "");
stamper.AcroFields.SetField("CurrentTwoDigitYear", date.ToString("yy"));
stamper.FormFlattening = true;
stamper.Close();
pdfReader.Close();
Response.AddHeader("Content-Disposition", "attachment; filename=YourPDF.pdf");
Response.ContentType = "application/pdf";
Response.BinaryWrite(output.ToArray());
Response.End();
}
示例3: GetFriendlyMonthName
/// <summary>
/// Get the friendly name for a month index
/// </summary>
/// <param name="yearAndMonth">The year and month in yyyyMM format</param>
/// <returns>The friendly month name</returns>
public virtual string GetFriendlyMonthName(int yearAndMonth)
{
if (yearAndMonth > 99999)
{
var month = int.Parse(yearAndMonth.ToString().Substring(4, 2));
DateTimeFormatInfo dtft = new DateTimeFormatInfo();
return dtft.GetMonthName(month);
}
return "[unknown]";
}
示例4: GetMonthName
public static string GetMonthName(this string monthCode)
{
int monthNumber;
if (!int.TryParse(monthCode, out monthNumber) || monthNumber < 1 || monthNumber > 12)
{
throw new InvalidMonthException("An invalid month number was passed", monthCode);
}
var formatInfo = new DateTimeFormatInfo();
return formatInfo.GetMonthName(monthNumber).ToLower();
}
示例5: AddArchives
private void AddArchives()
{
var dateTimeFormatInfo = new DateTimeFormatInfo();
var group = _postsList.GroupBy(p => new { p.PostAddedDate.Year, p.PostAddedDate.Month })
.OrderByDescending(g => g.Key.Year)
.ThenByDescending(g => g.Key.Month);
var archives = @group.Select(g => new Archive
{
MonthYear = string.Format("{0} {1} ({2})", dateTimeFormatInfo.GetMonthName(g.Key.Month), g.Key.Year, g.Count()),
Year = g.Key.Year.ToString(CultureInfo.InvariantCulture),
Month = g.Key.Month.ToString("00")
}).ToList();
Archives.AddRange(archives);
}
示例6: AddArchives
private void AddArchives()
{
var dateTime = GetDateTime();
var currentYear = dateTime.Year;
var currentMonth = dateTime.Month;
var dateTimeFormatInfo = new DateTimeFormatInfo();
var post = _postsList.OrderByDescending(p => p.PostEditedDate).LastOrDefault();
if (post != null)
{
var endYear = post.PostAddedDate.Year;
while (currentYear >= endYear)
{
if (_postsList.Any(p => p.PostAddedDate.Year == currentYear && p.PostAddedDate.Month == currentMonth))
{
Archives.Add(new Archive
{
Year = currentYear.ToString(),
Month = currentMonth.ToString("00"),
MonthYear = string.Format("{0} {1}", dateTimeFormatInfo.GetMonthName(currentMonth), currentYear)
});
}
if (currentMonth - 1 < 1)
{
currentMonth = 12;
currentYear--;
}
else
{
currentMonth--;
}
}
}
}
示例7: Index
public ActionResult Index(SearchViewModel model)
{
var ci = new CultureInfo("es-CO");
model.Specialties = new SpecialtyAppService().GetAllSpecialty();
model.Medics = new EmployeeAppService().GetAllMedics();
List<TimeSlot> lst = new TimeSlotAppService().GetAllTimeSlotWithoutAppoitment();
if (model.EmployeeId != -1)
{
lst = ApplyFilterEmployee(lst, model.EmployeeId);
}
if (model.SpecialtyId != -1)
{
lst = ApplyFilterSpecialty(lst, model.SpecialtyId);
}
if (!String.IsNullOrEmpty(model.GeoCityId) || model.GeoCityId!= "-1")
{
lst = ApplyFilterCity(lst, model.GeoCityId);
}
if (!String.IsNullOrEmpty(model.FromDate) && !String.IsNullOrEmpty(model.ToDate))
{
var fromDate = DateTime.ParseExact(model.FromDate, "dd/MM/yyyy", ci);
var toDate = DateTime.ParseExact(model.ToDate, "dd/MM/yyyy", ci);
lst = ApplyFilterDate(lst, fromDate,toDate);
}
model.AvailableSlot = new List<TimeSlotViewModel>();
System.Globalization.DateTimeFormatInfo mfi = new System.Globalization.DateTimeFormatInfo();
foreach (var itm in lst)
{
var emp = new EmployeeAppService().GetEmployee(itm.Schedule.EmployeeId);
var itmVm = new TimeSlotViewModel
{
ScheduleId = itm.ScheduleId,
MonthName = itm.Schedule.Month,
TimeSlotId = itm.TimeSlotId,
OfficeId = itm.OfficeId,
Day = itm.Day,
StartTime = itm.StartTime,
EndTime = itm.EndTime,
StartTimeText = itm.StartTime.ToShortTimeString(),
EndTimeText = itm.EndTime.ToShortTimeString(),
OfficeAddress = string.Format("Medico:{0}({1}) {2},{3}", emp.FullName, itm.Office.Address, itm.Office.Number, itm.Office.GeoCity.Name),
DayName = string.Format("{0},{1} de {2} de {3}", new DateTime(itm.Schedule.Year, itm.Schedule.Month, itm.Day).DayOfWeek.ToString(ci), itm.Day,mfi.GetMonthName(itm.Schedule.Month).ToString(),itm.Schedule.Year)
};
model.AvailableSlot.Add(itmVm);
}
Session["AvailableSchedule"] = model.AvailableSlot;
return View(model);
}
示例8: GetTimeline
/// <summary>
///
/// </summary>
/// <param name="archiveList"></param>
/// <returns></returns>
/// <remarks>
/// 2013
/// Jan x 3
/// 2012
/// 2011
/// 2010
/// 2000s (2000 - 2009)
/// 2009 x 30
/// 1990s (1990 - 1999)
///
/// - only clicking on the child node will show posts
/// - clicking on parent node will simply expand
/// - only inner node has post count
/// - only active parent is highlighted
/// - active child is bolded
/// - parent that ends with "s", e.g. 2000s, covers 10 years
/// </remarks>
public static List<Timeline> GetTimeline(Nav nav)
{
string key = BlogHelper.GetCacheKey_Timeline(nav.Slug);
List<Timeline> timeList = SiteCache.Get(key) as List<Timeline>;
if (timeList != null) return timeList;
// get
List<Archive> archiveList = BlogApp.GetArchives(nav);
// transform archive list to timeline
timeList = new List<Timeline>();
DateTimeFormatInfo dtInfo = new DateTimeFormatInfo();
foreach (var archive in archiveList)
{
if (archive.Year < 2020 && archive.Year > 2010)
{
Timeline time = timeList.Find(t => t.Label == archive.Year.ToString());
if (time == null)
{
time = new Timeline(archive.Nav) { Label = archive.Year.ToString(), Year = archive.Year, Month = archive.Month, Children = new List<Timeline>() };
time.Children.Add(new Timeline(archive.Nav) { Label = dtInfo.GetMonthName(archive.Month), Count = archive.MonthlyPostCount, Year = archive.Year, Month = archive.Month });
timeList.Add(time);
}
else
{
time.Children.Add(new Timeline(archive.Nav) { Label = dtInfo.GetMonthName(archive.Month), Count = archive.MonthlyPostCount, Year = archive.Year, Month = archive.Month });
}
}
else if (archive.Year < 2010 && archive.Year > 2000)
{
Timeline time = timeList.Find(t => t.Label == "2010s");
if (time == null)
{
time = new Timeline(archive.Nav) { Label = "2010s", Children = new List<Timeline>() };
time.Children.Add(new Timeline(archive.Nav)
{
Label = archive.Year.ToString(),
Count = archive.YearlyPostCount,
Year = archive.Year
}); // only show year for decades
timeList.Add(time);
}
else
{
if (time.Children.Find(t => t.Label == archive.Year.ToString()) == null)
time.Children.Add(new Timeline(archive.Nav)
{
Label = archive.Year.ToString(),
Count = archive.YearlyPostCount,
Year = archive.Year
});
}
}
}
SiteCache.Add(key, timeList, new TimeSpan(0, 2, 0));
return timeList;
}
示例9: MatchMonthName
/*=================================MatchMonthName==================================
**Action: Parse the month name from string starting at str.Index.
**Returns: A value from 1 to 12 indicating the first month to the twelveth month.
**Arguments: str: a __DTString. The parsing will start from the
** next character after str.Index.
**Exceptions: FormatException if a month name can not be found.
==============================================================================*/
private static bool MatchMonthName(ref __DTString str, DateTimeFormatInfo dtfi, ref int result) {
int maxMatchStrLen = 0;
result = -1;
if (str.GetNext()) {
//
// Scan the month names (note that some calendars has 13 months) and find
// the matching month name which has the max string length.
// We need to do this because some cultures (e.g. "vi-VN") which have
// month names with the same prefix.
//
int monthsInYear = (dtfi.GetMonthName(13).Length == 0 ? 12: 13);
for (int i = 1; i <= monthsInYear; i++) {
String searchStr = dtfi.GetMonthName(i);
int matchStrLen = searchStr.Length;
if ( dtfi.HasSpacesInMonthNames
? str.MatchSpecifiedWords(searchStr, false, ref matchStrLen)
: str.MatchSpecifiedWord(searchStr)) {
if (matchStrLen > maxMatchStrLen) {
maxMatchStrLen = matchStrLen;
result = i;
}
}
}
// Search genitive form.
if ((dtfi.FormatFlags & DateTimeFormatFlags.UseGenitiveMonth) != 0) {
int tempResult = str.MatchLongestWords(dtfi.MonthGenitiveNames, ref maxMatchStrLen);
// We found a longer match in the genitive month name. Use this as the result.
// The result from MatchLongestWords is 0 ~ length of word array.
// So we increment the result by one to become the month value.
if (tempResult >= 0) {
result = tempResult + 1;
}
}
// Search leap year form.
if ((dtfi.FormatFlags & DateTimeFormatFlags.UseLeapYearMonth) != 0) {
int tempResult = str.MatchLongestWords(dtfi.internalGetLeapYearMonthNames(), ref maxMatchStrLen);
// We found a longer match in the leap year month name. Use this as the result.
// The result from MatchLongestWords is 0 ~ length of word array.
// So we increment the result by one to become the month value.
if (tempResult >= 0) {
result = tempResult + 1;
}
}
}
if (result > 0) {
str.Index += (maxMatchStrLen - 1);
return (true);
}
return false;
}
示例10: FormatMonth
private static String FormatMonth(int month, int repeatCount, DateTimeFormatInfo dtfi)
{
Contract.Assert(month >=1 && month <= 12, "month >=1 && month <= 12");
if (repeatCount == 3)
{
return (dtfi.GetAbbreviatedMonthName(month));
}
// Call GetMonthName() here, instead of accessing MonthNames property, because we don't
// want a clone of MonthNames, which will hurt perf.
return (dtfi.GetMonthName(month));
}
示例11: InitializedMonthList
private void InitializedMonthList()
{
DateTime now = DateTime.Now;
for (int i = 1; i <= 12; i++)
{
DateTimeFormatInfo mfi = new DateTimeFormatInfo();
ddListMonth.Items.Add(new ListItem(mfi.GetMonthName(i), i.ToString()));
}
}
示例12: TestInvalidDayOfWeek
public void TestInvalidDayOfWeek()
{
DateTimeFormatInfo info1 = new DateTimeFormatInfo();
Assert.Throws<ArgumentOutOfRangeException>(() =>
{
info1.GetMonthName(c_MIN_MONTH_VALUE - 1);
});
DateTimeFormatInfo info2 = new DateTimeFormatInfo();
Assert.Throws<ArgumentOutOfRangeException>(() =>
{
info2.GetMonthName(c_MAX_MONTH_VALUE + 1);
});
}
示例13: FormatHebrewMonthName
private static string FormatHebrewMonthName(DateTime time, int month, int repeatCount, DateTimeFormatInfo dtfi)
{
if (dtfi.Calendar.IsLeapYear(dtfi.Calendar.GetYear(time)))
{
return dtfi.internalGetMonthName(month, MonthNameStyles.LeapYear, repeatCount == 3);
}
if (month >= 7)
{
month++;
}
if (repeatCount == 3)
{
return dtfi.GetAbbreviatedMonthName(month);
}
return dtfi.GetMonthName(month);
}
示例14: GetMonthName
private static string GetMonthName(int monthNumber)
{
DateTimeFormatInfo dtf = new DateTimeFormatInfo();
return dtf.GetMonthName(monthNumber);
}
示例15: MatchAbbreviatedMonthName
private static bool MatchAbbreviatedMonthName(ref __DTString str, DateTimeFormatInfo dtfi, ref int result)
{
int maxMatchStrLen = 0;
result = -1;
if (str.GetNext())
{
int num2 = (dtfi.GetMonthName(13).Length == 0) ? 12 : 13;
for (int i = 1; i <= num2; i++)
{
string abbreviatedMonthName = dtfi.GetAbbreviatedMonthName(i);
int length = abbreviatedMonthName.Length;
if ((dtfi.HasSpacesInMonthNames ? str.MatchSpecifiedWords(abbreviatedMonthName, false, ref length) : str.MatchSpecifiedWord(abbreviatedMonthName)) && (length > maxMatchStrLen))
{
maxMatchStrLen = length;
result = i;
}
}
if ((dtfi.FormatFlags & DateTimeFormatFlags.UseLeapYearMonth) != DateTimeFormatFlags.None)
{
int num5 = str.MatchLongestWords(dtfi.internalGetLeapYearMonthNames(), ref maxMatchStrLen);
if (num5 >= 0)
{
result = num5 + 1;
}
}
}
if (result > 0)
{
str.Index += maxMatchStrLen - 1;
return true;
}
return false;
}