如何获得月份名称

时间:2015-04-08 11:06:51

标签: c# linq

    using (DataAccessAdapter adapter = new DataAccessAdapter())
       {
         LinqMetaData meta = new LinqMetaData(adapter);
         var datas = (from x in meta.Table
           where x.DateCreated >= startDate && x.DateCreated <= endDate && x.ViaTo > 0 && !x.Cancelled
           group x by new { month = x.DateCreated.Value.Month } into g
           select new
           {
            MonthNr = g.Key,
            //MonthName = ?
            TotalMonthAmount = g.Sum(x => x.Amount)
            });
.....
       }

startDate&amp; endDate是有效日期。

我只获得月份编号,如何获取DateCreated的月份名称?

3 个答案:

答案 0 :(得分:4)

您可以使用此功能获取月份名称:

CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(monthNumber);

答案 1 :(得分:0)

new {month = x.DateCreated.Value.Month.ToString(“MMM”)}

答案 2 :(得分:0)

我想你是在询问有关Month属性的事。检查一下:

using System;

class Program
{
    static void Main()
    {
        DateTime now = DateTime.Now;
        //
        // Write the month integer and then the three-letter month.
        //
        Console.WriteLine(now.Month); //outputs 5
        Console.WriteLine(now.ToString("MMM")); //outputs May
    }
}