Use DateTime.parse() to solve this error.

Strftime deals with date objects. You may be trying this with String Value.

The following code converts the
“time” to new “timezone value”.

Paste the following code in the application.rb or wherever you like

def convert_zone(to_zone)

#notify the current timezone
original_zone = ENV[”TZ”]
#finds UTC time
utc_time = dup.gmtime
#change the zone into the requested zone(parameter
value)
ENV[”TZ”] = to_zone
#convert the UTC time to local time in the changed
zone
to_zone_time = utc_time.localtime
#Now change the zone back to the original zone
ENV[”TZ”] = original_zone
return to_zone_time

end

This function takes the “timezone”(to which you want to convert) as a
parameter and takes control of the rest.

(Eg.)

t = Time.now
# => Sun Sep 09 01:46:40 UTC 2001
t.convert_zone(”Asia/Calcutta”) …

I came across this error when dealing with
Date attribute.

Rails active record throws this error when you try to assign the
“datetime” value to a date attribute.

Changing the db field accordingly fixes this
error.

Export

mysqldump -u username -p password database_name >
FILE.sql

Import

mysqldump -u username -p password database_name <
FILE.sql

Page 39 of 46« First...«3738394041»...Last »

Categories and Tags

Advertising