태그 보관물: datetime

datetime

시간없이 Rails DateTime.now 것을 보여줍니다 .DateTime.now => Sat,

DateTime.now를 사용하여 현재 날짜를 가져 와서 시간을 “제거”해야합니다.

예를 들어, 이것은 내가 원하지 않는 것을 보여줍니다 .DateTime.now => Sat, 19 Nov 2011 18:54:13 UTC +00:00

내가 어떻게이 공연 할이 원하는 :DateTime.now.some_operation => 2011-11-06 00:00:00 UTC



답변

다음 중 하나를 사용할 수 있습니다.

  • DateTime.current.midnight
  • DateTime.current.beginning_of_day
  • DateTime.current.to_date


답변

필요한 것은 strftime 함수입니다.

Time.now.strftime("%Y-%d-%m %H:%M:%S %Z")


답변

어때 Date.today.to_time?


답변

에 만족하는 require 'active_support/core_ext'경우 다음을 사용할 수 있습니다.

DateTime.now.midnight # => Sat, 19 Nov 2011 00:00:00 -0800


답변

다음을 사용할 수 있습니다.

Date.current


답변

시간없이 오늘 날짜를 원한다면 Date.today


답변

그것을 알아 냈습니다. 이것은 작동합니다 :

DateTime.now.in_time_zone.midnight