日期与ruby Date.today和DateTime.now错误 [英] Wrong date with ruby Date.today and DateTime.now

查看:197
本文介绍了日期与ruby Date.today和DateTime.now错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用RVM安装了ruby-1.8.6-p383。系统ruby是1.9.1_p378-1



我从Date.today和DateTime.now得到错误的日期,当使用ruby 1.8 ..而Time.now是正确的:

  irb(main):002:0> DateTime.now.to_s 
=> 2126--1-10618T11:23:43 + 00:00
irb(main):004:0> Date.today.to_s
=> 2126--1-10618
irb(main):005:0> Time.now
=> Thu Jan 28 11:55:27 +0000 2010

一切都很好,如果我切换到ruby 1.9:

  irb(main):003:0> DateTime.now.to_s 
=> 2010-01-28T11:58:51 + 00:00
irb(main):004:0> Date.today.to_s
=> 2010-01-28
irb(main):005:0> Time.now
=> 2010-01-28 11:59:05 +0000

有关如何让DateTime工作的任何建议正确的ruby 1.8将非常感谢!

解决方案

我偶然发现类似的问题,并得到3种不同的解决方案,我试过2两人都工作。从这里阅读更多信息:



http://www.ruby-forum.com/topic/210647



Jarmo


I've installed ruby-1.8.6-p383 with RVM. System ruby is 1.9.1_p378-1

I'm getting the wrong date from Date.today and DateTime.now when using ruby 1.8.. Whereas Time.now is correct:

irb(main):002:0> DateTime.now.to_s
=> "2126--1-10618T11:23:43+00:00"
irb(main):004:0> Date.today.to_s
=> "2126--1-10618"
irb(main):005:0> Time.now
=> Thu Jan 28 11:55:27 +0000 2010

All is well if I switch to ruby 1.9:

irb(main):003:0> DateTime.now.to_s
=> "2010-01-28T11:58:51+00:00"
irb(main):004:0> Date.today.to_s
=> "2010-01-28"
irb(main):005:0> Time.now
=> 2010-01-28 11:59:05 +0000

Any advice on how to get DateTime to work properly in ruby 1.8 would be most appreciated!

解决方案

I stumbled upon similar problem and got 3 different solutions, which i tried 2 of and both worked. Read more about it from here:

http://www.ruby-forum.com/topic/210647

Jarmo

这篇关于日期与ruby Date.today和DateTime.now错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆