English 中文(简体)
你们怎样获得时间。 在贵时区休息一段时间?
原标题:How do you get DateTime.parse to return a time in your time zone?
  • 时间:2011-01-02 02:56:33
  •  标签:
  • ruby
  • date

我需要这样做。

 require  date 
 DateTime.parse "Mon, Dec 27 6:30pm"

返回厄立特里亚国防军时区6:30pm,但返回美国联邦行政法院。 我怎么能拿到无害环境技术的时代,还是把UTC改成具有6:30pm价值的EDT日?

最佳回答

最后答复:-

require  date 
estHoursOffset = -5
estOffset = Rational(estHoursOffset, 24)
date = (DateTime.parse("Mon, Dec 27 6:30pm") - (estHoursOffset/24.0)).new_offset(estOffset)

(or -4 for EDT)

问题回答

页: 1

require  time 
ENV["TZ"] = "US/Eastern"
Time.parse("Mon, Dec 27 6:30pm").to_datetime
=> #<DateTime: 2011-12-27T18:30:00-05:00 (117884327/48,-5/24,2299161)> 

在铁路,这对我来说是出色的。

DateTime.parse "Mon, Dec 27 6:30pm #{Time.zone}"

该公司在Vyilla Duncan取得了一些工作。

DateTime#change()

You can try using change() after parsing it to alter the timezone offset:

DateTime.parse( "Mon, Dec 27 6:30pm" ).change( offset:  -0400  )
# => Wed, 27 Dec 2017 18:30:00 -0400

你们也可以仅仅使用时间:

DateTime.parse( "Mon, Dec 27 6:30pm" ).change( offset:  -4  )
# => Wed, 27 Dec 2017 18:30:00 -0400

www.un.org/Depts/DGACM/index_spanish.htm 但是,如果谨慎,你不能使用一种分类:。

DateTime.parse( "Mon, Dec 27 6:30pm" ).change( offset: -4 )
# => Wed, 27 Dec 2017 18:30:00 +0000

如果你需要确定在时间区基础上使用的正确数字,你可以做这样的事情:

offset = ( Time.zone_offset( EDT ) / 1.hour ).to_s
# => "-4"

DateTime.parse( "Mon, Dec 27 6:30pm" ).change( offset: offset )
# => Wed, 27 Dec 2017 18:30:00 -0400

您也可使用<代码>change()以人工方式确定<代码>的其他部分,如设置hour至中午:

DateTime.parse( "Mon, Dec 27 6:30pm" ).change( offset:  -4 , hour: 12 )
# => Wed, 27 Dec 2017 12:00:00 -0400

www.un.org/Depts/DGACM/index_spanish.htm 注意这一点,因为你可以看到,它清除了记录。

http://api.rubyonrails.org/v5.1/classes/Datetime.html#method-i-change”rel=“noreferer” http://api.rubyonrails.org/v5.1/classes/Datetime.html#method-i-change

如果你重新使用铁路积极支持:

"Mon, Dec 27 6:30pm".in_time_zone(-4.hours).to_datetime
# => Mon, 27 Dec 2021 18:30:00 -0400
Time.find_zone(-4.hours).parse("Mon, Dec 27 6:30pm").to_datetime
# => Mon, 27 Dec 2021 18:30:00 -0400

如果你想利用当地日光储蓄时间规则,你可以使用:

"Mon, Dec 27 6:30pm".in_time_zone("Eastern Time (US & Canada)")
# => Mon, 27 Dec 2021 18:30:00 EST -05:00 
Time.find_zone("Eastern Time (US & Canada)").parse("Mon, Dec 27 6:30pm")
# => Mon, 27 Dec 2021 18:30:00 EST -05:00
Time.find_zone("Eastern Time (US & Canada)").parse("Mon, Dec 27 6:30pm").to_datetime
# => Mon, 27 Dec 2021 18:30:00 -0500
Time.find_zone("Eastern Time (US & Canada)").parse("Mon, Jun 27 6:30pm")
# => Sun, 27 Jun 2021 18:30:00 EDT -04:00
Time.find_zone("Eastern Time (US & Canada)").parse("Mon, Jun 27 6:30pm").to_datetime
# => Sun, 27 Jun 2021 18:30:00 -0400
Time.find_zone("EST5EDT").parse("Mon, Jun 27 6:30pm").to_datetime
# => Sun, 27 Jun 2021 18:30:00 -0400

6月份通知自动发给厄立特里亚国防军(-0400),因为这一日期与12月的日期相反。

To force EST regardless if date is within DST or not:

Time.find_zone("EST").parse("Mon, Jun 27 6:30pm")
# => Sun, 27 Jun 2021 18:30:00 EST -05:00
Time.find_zone("EST").parse("Mon, Jun 27 6:30pm").to_datetime
# => Sun, 27 Jun 2021 18:30:00 -0500




相关问题
Mysql compaire two dates from datetime?

I was try to measure what is faster and what should be the best way to compare two dates, from datetime record in MySql db. There are several approaches how to grab a date from date time, but I was ...

iPhone Date Picker rolls over to 2010 on December 27th?

So I implemented a UIDatepicker in one of my applications for scheduling and autodialing teleconferences... everything is pretty much ready to go except, while testing I noticed that when the date ...

Convert date Python

I have MMDDYY dates, i.e. today is 111609 How do I convert this to 11/16/2009, in Python?

specifying date format when using $form->inputs() in CakePHP

I am wondering if there is a way to specify the date format in the forms created using CakePHP s $form->inputs(); Please note that this is not the individual $form->input() but instead $form->inputs() ...

NSDateFormat, super simple! Where am I screwing up?

Ok, this is really simple, maybe I m a getting a bit burnt out, but seems like it should work, Query XML feed, put out date string, format, display in a cell. The issue is I m a getting a NULL ...

sqlite writing a date into an email

I am exporting a date value from sqlite and placing it into an email. The date appears like this 279498721.322872 I am using Objective C in an Iphone App. Does anyone know how to make this export ...

热门标签