我用silverlight在VS 2012中为windows phone编写了一个程序,现在我正在尝试将我的程序导入VS 2015通用应用程序。在我的程序中,我需要得到给定日期的周数,因为他的我写了以下函数
public int WeekNumber(DateTime date)
{
GregorianCalendar cal = new GregorianCalendar(GregorianCalendarTypes.Localized);
return cal.GetWeekOfYear(date, CalendarWeekRule.FirstDay, DayOfWeek.Monday);
}但是在winrt中,没有GregorianCalendar,我也尝试以这种方式创建日历:
Windows.Globalization.Calendar cal = new Windows.Globalization.Calendar();然后试着在一年的每周,但没有这样的方法。
是否知道如何在winRT中获得给定日期的周数。
非常感谢。
发布于 2015-05-22 05:22:04
我发现,在使用Windows.Globalization.Calendar时,您没有GetWeekOfYear方法,但是如果使用System.Globalization.Calendar,则会使GetWeekOfYear方法正常工作。基于此,下面的代码可以根据需要工作。
public int WeekNumber(DateTime date)
{
DateTimeFormatInfo dfi = DateTimeFormatInfo.CurrentInfo;
System.Globalization.Calendar cal = dfi.Calendar;
return cal.GetWeekOfYear(date, CalendarWeekRule.FirstDay, DayOfWeek.Monday);
}https://stackoverflow.com/questions/30381805
复制相似问题