Ruby: How modify Timezone without change time [duplicate] - ruby-on-rails

This question already has answers here:
Ruby / Rails - Change the timezone of a Time, without changing the value
(14 answers)
Closed 7 years ago.
Ruby/Rails How to do this.
only modify the timezone of Time
2015-01-01 00:00:00 +0900 => 2015-01-01 00:00:00 +0000

take this date in variable say currentDateTime:
then use following:
currentDateTime.change(:offset => "+0000")

Related

Formatting a date - Rails [duplicate]

This question already has answers here:
Rails formatting date
(4 answers)
Closed 4 years ago.
I have a variable containing a date in this form: (2018-03-21 18:49:49 UTC)
and I would like to display in this form: (day / month / year) but I can not find a solution. Do you have an idea ? Thank you !
Well, I guess this could work.
print "What year?"
year = gets.chomp!
print "What number month?"
month = gets.chomp!
print "What number day?"
day = gets.chomp!
puts "#{day}/#{month}/#{year}"
I'm new to ruby but I think this should work.

Ruby/Rails date conversion using strptime. MM/DD/YY [duplicate]

This question already has answers here:
Rails formatting date
(4 answers)
Closed 5 years ago.
I'm parsing PDF which returns date as string in format "04/27/17". How can I convert these strings to format for storing as date in rails?
Thanks!
Date::strptime can initialize a date object from a wacky US-based Y2K-unaware date format. Then if you have an active record class called MyObject with a date field called sweet_date, it would go like this:
date = Date::strptime("04/27/17", "%m/%d/%y") # returns Thu, 27 Apr 2017
object = MyObject.first
object.sweet_date = date
object.save # true

How do I parse non-traditional dates in golang? [duplicate]

This question already has an answer here:
Date parsing in Go
(1 answer)
Closed 6 years ago.
I have this date, in this format:
25.04.2016
I need to parse this into a Golang time object so that I can store it in my DB.
What is the best way to do so? I can't find a standard parsing format that will do so.
To parse a date in go you provide a format string that represents the date Mon Jan 2 15:04:05 MST 2006 so in this case it would look like;
t, _ := time.Parse("02.01.2006", "25.04.2016")
(play ground example; https://play.golang.org/p/6E9zshNeFG )
Check the packages docs here; https://golang.org/pkg/time/#example_Parse
I believe the arbitrary date you use as the example format is the first day of the Go programming language.

How to convert NSString into NSDate [duplicate]

This question already has answers here:
NSDate is 5 hours off
(4 answers)
Closed 7 years ago.
I want to convert my label.text into NSDate My formatter is MM/dd/yyyy. So I convert it like this.
mydate1=[dateFormatter dateFromString:depdate1txt.text];
My label value is (lldb) po depdate1txt.text
12/13/2015
But when I check the mydate1 it shows as (lldb) po mydate1
2015-12-12 18:30:00 +0000
Why date has changed into 12th december in 2015?
Please help me.
Thanks
When you print the date with po it's not formatting it - that's the base value. All dates are stored as a timestamp and only formatted when you explicitly format them.
The po command just takes a default formatter to show the date.
Oh, and the 'date change' is because of your timezone - the printed date is GMT +0.

Convert week number to a date [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How do I get a Date from a week number?
Finding the date for a given week number
How would I convert a week number (%W) back to a certain date. For example converting week 20 to May 15, 2012.
Check Date#commercial:
Date.commercial(2012, 20)
#=> Mon, 14 May 2012

Resources