[英]WeekNumber in WinRT
i wrote a program in VS 2012 for windows phone using silverlight, now i am trying to import my program to VS 2015 Universal app. 我使用Silverlight在VS 2012中为Windows Phone编写了一个程序,现在我正尝试将程序导入VS 2015 Universal应用程序。 In my program i need to get the week number of given date, for his i wrote followin function
在我的程序中,我需要获取给定日期的星期数,因为他写了followin函数
public int WeekNumber(DateTime date)
{
GregorianCalendar cal = new GregorianCalendar(GregorianCalendarTypes.Localized);
return cal.GetWeekOfYear(date, CalendarWeekRule.FirstDay, DayOfWeek.Monday);
}
But in winrt, there is no GregorianCalendar, i also try to create calender this way: 但是在winrt中,没有GregorianCalendar,我也尝试通过这种方式创建日历:
Windows.Globalization.Calendar cal = new Windows.Globalization.Calendar();
and then try to get weekofyear, but there is no such method. 然后尝试获取一周的时间,但是没有这种方法。
Any idea how to get weeknumber of given date in winRT. 任何想法如何在winRT中获得给定日期的周数。
thanks a lot. 非常感谢。
I found out that, when using Windows.Globalization.Calendar
, you don't have GetWeekOfYear
method, but if you use System.Globalization.Calendar
, then you get the GetWeekOfYear
method working. 我发现,使用
Windows.Globalization.Calendar
,没有GetWeekOfYear
方法,但是如果使用System.Globalization.Calendar
,则可以使GetWeekOfYear
方法正常工作。 Based on this, below code working as needed. 基于此,以下代码可根据需要工作。
public int WeekNumber(DateTime date)
{
DateTimeFormatInfo dfi = DateTimeFormatInfo.CurrentInfo;
System.Globalization.Calendar cal = dfi.Calendar;
return cal.GetWeekOfYear(date, CalendarWeekRule.FirstDay, DayOfWeek.Monday);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.