سؤال

In my fixtures for unit testing, I have something like this:

time: <%= Time.now %>

This will give me the time based on the machine's time zone. I want to get the time in UTC, I tried this:

time: <%= Date.tomorrow.in_time_zone('UTC') %>

It says, in_time_zone is undefined. How can I get the UTC date/time in the fixtures?

Thanks,

هل كانت مفيدة؟

المحلول

It will show current time in UTC:-

Time.now.utc

Example:--

1.9.3-p385 :003 > Time.now.utc
=> 2014-04-25 19:29:03 UTC 
1.9.3-p385 :004 > 

نصائح أخرى

Try giving like this

<%= Time.now.utc.in_time_zone %>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top