我正在迭代DayOfWeek Enum,如下所示:
foreach (DayOfWeek day in Enum.GetValues(typeof(DayOfWeek)))
{
// Add stuff to a list
}
Run Code Online (Sandbox Code Playgroud)
而我的问题是,我希望我的枚举从星期一而不是星期日开始.
我试着这样做:
CultureInfo ci = Thread.CurrentThread.CurrentCulture;
ci.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Monday;
Run Code Online (Sandbox Code Playgroud)
但是foreach循环仍然在周日开始.
我怎样才能做到这一点 ?
我的最后一个想法是将我的结果列表重新排序到我想要的那天,但这意味着更多的迭代.
谢谢 !
我在具有区域设置的计算机上运行SQL Server 2008,该区域设置将星期一作为一周的第一天.如果我在表中创建一个计算列来计算日期字段的星期几,那么我得到2表示星期一而不是1.
是否需要设置表或数据库或服务器的某些属性?
我正在将现有的应用程序从Joda-Time移植到Java 8 java.time.
我遇到了一个问题,解析包含"星期几"值的日期/时间字符串在我的单元测试中触发了异常.
解析时:
2016-12-21 20:50:25 12月周三+0000 3
使用格式:
yyyy'-'MM'-'dd' 'HH':'mm':'ss' 'EEEE' 'MMMM' 'ZZ' 'e
Run Code Online (Sandbox Code Playgroud)
我明白了:
java.time.format.DateTimeParseException:
Text '2016-12-21 20:50:25 Wednesday December +0000 3'
could not be parsed: Conflict found:
Field DayOfWeek 3 differs from DayOfWeek 2 derived from 2016-12-21
Run Code Online (Sandbox Code Playgroud)
当让它DateTimeFormatter表明它所期望的时候:
String logline = "2016-12-21 20:50:25 Wednesday December +0000";
String format = "yyyy'-'MM'-'dd' 'HH':'mm':'ss' 'EEEE' 'MMMM' 'ZZ";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format).withLocale(Locale.ENGLISH);;
ZonedDateTime dateTime = formatter.parse(logline, ZonedDateTime::from);
format = "yyyy'-'MM'-'dd' 'HH':'mm':'ss' 'EEEE' 'MMMM' 'ZZ' 'e";
formatter = …Run Code Online (Sandbox Code Playgroud) 我有周数据,表格yyyy-ww中ww的周数是两位数.数据跨越2007-01到2010-30.周计数会议是ISO 8601,正如您在维基百科的"周数"文章中所看到的,偶尔会在一年内达到53周.例如,2009年该系统有53周,请参阅此ISO 8601日历中的周数.(见其他年份;根据维基百科的文章,第53周相当罕见.)
基本上我想阅读周日期,将其转换为Date对象并将其保存到一个单独的列中data.frame.作为测试,我将Date对象重新转换为yyyy-ww格式format([Date-object], format = "%Y-%W",并在此处抛出错误2009-53.那个星期没有被解释为日期R.这是非常奇怪的,因为没有第53周(在ISO 8601标准中)的2007-53其他年份被转换为罚款,例如,而其他年份也没有第53周(在ISO 8601标准中)也失败,例如2008-53
以下最小示例演示了该问题.
最小的例子:
dates <- c("2009-50", "2009-51", "2009-52", "2009-53", "2010-01", "2010-02")
as.Date(x = paste(dates, 1), format = "%Y-%W %w")
# [1] "2009-12-14" "2009-12-21" "2009-12-28" NA "2010-01-04"
# [6] "2010-01-11"
other.dates <- c("2007-53", "2008-53", "2009-53", "2010-53")
as.Date(x = paste(other.dates, 1), …Run Code Online (Sandbox Code Playgroud) 如何通过包含星期几名称的varchar列来订购mysql结果?
请注意,星期一应该先行,而不是星期日.
如果我使用这个功能,pd.DatetimeIndex(dfTrain['datetime']).weekday我得到当天的数字,但我没有找到任何给出de day名称的函数...所以我需要将0转换为星期一,1转换为Tuestday,依此类推.
以下是我的数据框示例:
datetime season holiday workingday weather temp atemp humidity windspeed count
0 2011-01-01 00:00:00 1 0 0 1 9.84 14.395 81 0.0000 16
1 2011-01-01 01:00:00 1 0 0 1 9.02 13.635 80 0.0000 40
2 2011-01-01 02:00:00 1 0 0 1 9.02 13.635 80 0.0000 32
3 2011-01-01 03:00:00 1 0 0 1 9.84 14.395 75 0.0000 13
4 2011-01-01 04:00:00 1 0 0 1 9.84 14.395 75 0.0000 1
5 2011-01-01 05:00:00 1 0 …Run Code Online (Sandbox Code Playgroud) 愚蠢的问题.鉴于日期时间的日期,我知道它是星期二,例如我怎么知道它的tue = 2和mon = 1等...
谢谢
可能重复:
如何确定给定日期是否是该月的第N个工作日?
我怎么得到这个月的第n个工作日?
例如:
2010年7月的第二个星期一= 2010年12月7日.
寻找像这样的功能:
public DateTime GetNthWeekofMonth(DateTime date, int nthWeek, DayOfWeek dayofWeek)
{
//return the date of nth week of month
}
Run Code Online (Sandbox Code Playgroud)
从上面可以看出,函数的参数是("2010年7月的任何日期",2,星期一).
在C#中,给定一组任意的DayOfWeek终点(如DayOfWeek.Friday和DayOfWeek.Sunday),如何测试任意日期是否在这两天之间,包括?
例:
// result == true; Oct 23, 2010 is a Saturday
var result = InBetweenDaysInclusive(new DateTime(2010, 10, 23),
DayOfWeek.Friday,
DayOfWeek.Sunday);
// result == true; Oct 22, 2010 is a Friday
result = InBetweenDaysInclusive(new DateTime(2010, 10, 22),
DayOfWeek.Friday,
DayOfWeek.Sunday);
// result == true; Oct 24, 2010 is a Sunday
result = InBetweenDaysInclusive(new DateTime(2010, 10, 24),
DayOfWeek.Friday,
DayOfWeek.Sunday);
// result == false; Oct 25, 2010 is a Monday
result = InBetweenDaysInclusive(new DateTime(2010, 10, 25),
DayOfWeek.Friday,
DayOfWeek.Sunday);
Run Code Online (Sandbox Code Playgroud)
谢谢!
下面的代码给出了Nougat和pre-Nougat的不同结果.看看,如果你想要自己尝试一下.如果有人能解释我为什么并给出解决方案,我将不胜感激.
我想在所有Android版本上获得正确的WEEK_OF_YEAR值,具体取决于一周的第一天.我有一个时间表应用程序,我正在使用gregorianCalendar很多,所以我不想切换到另一个类/ lib.
//default first day of the week is Monday for replication. I live in the Netherlands, it's weird.
Locale l = new Locale("nl", "NL");
GregorianCalendar test = new GregorianCalendar(l);
test.set(Calendar.YEAR, 2017);
test.set(Calendar.MONTH, 0);
test.set(Calendar.DAY_OF_MONTH, 29);//this is a Sunday
int week = test.get(Calendar.WEEK_OF_YEAR);//should be 4
test.setFirstDayOfWeek(1);//Set it to Sunday
int week2 = test.get(Calendar.WEEK_OF_YEAR);//should be 5 but is 4 below nougat???
Run Code Online (Sandbox Code Playgroud)