我的阵列如下:
[Wed Jan 04 21:56:08 UTC 2012, Thu Jan 12:58:36 UTC 2012, Thu Jan 12 22:13:24 UTC 2012, Thu Jan 12 22:13:34 UTC 2012]
鲁比拉只有这一阵列才算出具体天数的最佳方式是什么? 2012年1月12日是三倍,但只算一次是我只关心月/日,而不是计算阵列中值的实际时间。
因此,过滤后这一阵列的总数应为2个不同的月/日/年值的2个。
我的阵列如下:
[Wed Jan 04 21:56:08 UTC 2012, Thu Jan 12:58:36 UTC 2012, Thu Jan 12 22:13:24 UTC 2012, Thu Jan 12 22:13:34 UTC 2012]
鲁比拉只有这一阵列才算出具体天数的最佳方式是什么? 2012年1月12日是三倍,但只算一次是我只关心月/日,而不是计算阵列中值的实际时间。
因此,过滤后这一阵列的总数应为2个不同的月/日/年值的2个。
这些指示或日期是否反对? 假设后一种情况,并更新阵列如下:datetime_arr
。
date_arr = datetime_arr.map &:to_date
# => [Wed, 04 Jan 2012, Thu, 12 Jan 2012, Thu, 12 Jan 2012, Thu, 12 Jan 2012]
date_arr.uniq!
# => [Wed, 04 Jan 2012, Thu, 12 Jan 2012]
date_arr.length
# => 2
我希望能够提供帮助。
虽然你已经接受了答复,但我要指出,如果你正在编辑一份项目清单,如果你想要为每一组别(如产出负责人)做一番事情的话,你应当使用。 方便:
require date
all_times = 5.times.map{ |i| Time.now + 3600 * 3 * i }
all_times.sort.group_by(&:to_date).each do |day, day_times|
puts "",day,"-"*40
day_times.each do |time|
puts time.strftime(" * %I:%M%P")
end
end
#=> 2012-01-12
#=> ----------------------------------------
#=> * 08:56pm
#=> * 11:56pm
#=>
#=> 2012-01-13
#=> ----------------------------------------
#=> * 02:56am
#=> * 05:56am
#=> * 08:56am
Problem with using times in Python. Terminal > Python >>> calendar.timegm(datetime.datetime.now().utctimetuple()) 1258449380 This time indicates GMT: Tue, 17 Nov 2009 09:16:20 GMT Eclipse ...
I have a Windows service running (C#, .NET 2.0) on Windows Server 2003 R2. In one server the System.Threading.Thread.CurrentThread.CurrentCulture is {en-AU} and in the other {en-US}. This has caused a ...
I m writing a bit of logic that requires treating null dates as meaning forever in the future (the date in question is an expiration date, which may or may not exist). Instead of putting in special ...
Short Question: What s the best date format to use in SQL Server? Long Explanation: We re converting our database from mysql to SQL Server. In mysql we always used int(11) to avoid the daylight ...
Our current app stores all dates via the server s datetime. I m thinking we need to update all datetime values in the database over to UTC time. Now for displaying these dates back to the user, I ...
Is there any way I can easily check if a string conforms to the SortableDateTimePattern ("s"), or do I need to write a regular expression? I ve got a form where users can input a copyright date (as a ...
I m currently working on some DateTime properties in a PropertyGrid in c#.Net. Im using the default drop-down datetime picker. My question: Is there any way to show the full date with the time? By ...
I love the new DATE datatype in SQL Server 2008, but when I compare a DATE field to a DATETIME field on a linked server (SQL 2005, in this case), like this: DECLARE @MyDate DATE SET @MyDate = CONVERT(...