Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert to a date and time without a time zone? [duplicate]

Tags:

timezone

r

dst

I have a time in the format of "1/1/2010 10:00". I would like to convert this to a time object. This time is a company time based in Calgary, Alberta. Please note there is no daylight savings adjustment made in the company time. How would I convert this to a date-time object?

like image 580
user2946746 Avatar asked Nov 09 '22 14:11

user2946746


1 Answers

You can use as.POSIXct to create the date/time object. Looks like Calgary, Alberta is UTC-07:00 as far as time zones go, so you can do

strptime("1/1/2010 10:00", format="%m/%d/%Y %H:%M", tz="Etc/GMT-7")

(assuming month/day/year format -- see ?strptime for other format options). Rather than specifying the true time zone, you could always use "GMT" instead.

like image 68
MrFlick Avatar answered Nov 15 '22 07:11

MrFlick