Hello, we are receiving some data, sample below - with a weird time/date stamp format, we need some help with R on converting this time date stamp to a useable field in R, date and time in a data-frame. The developer says its the number of milliseconds since midnight, January 1, 1970. sample: *1232558018624* --------------------- How do I interpret the time stamp? Is there a date, i need a date and time. site_id,survey_id,version_id,survey_start_ts,survey_question_id,start_ts,end_ts,answer 2,registration,1,1232558018625,z1,*1232558018624*,*1232558266179*,4 Answer: The timestamp is a number representing the exact date and time. it is the number of milliseconds since midnight, January 1, 1970. Are you using it in the DB or R? I am not sure about R's conversion of numbers and dates. is there a way to add a number of seconds or milliseconds to a date in R? [[alternative HTML version deleted]]
Since the starting date is the same as that of the POSIXct class, it should not be a big problem. Just divide by 1000. > as.POSIXct(1232558018624/1000, origin="1970-01-01") # throws an error if origin not set [1] "2009-01-21 17:13:38 EST" > > as.POSIXct(0/1000, origin="1970-01-01") [1] "1970-01-01 EST" -- David Winsemius On Jan 22, 2009, at 5:39 PM, zubin wrote:> Hello, we are receiving some data, sample below - with a weird time/ > date > stamp format, we need some help with R on converting this time date > stamp to a useable field in R, date and time in a data-frame. The > developer says its the number of milliseconds since midnight, > January 1, > 1970. > > sample: *1232558018624* > --------------------- > > > How do I interpret the time stamp? Is there a date, i need a date > and time. > site_id > ,survey_id > ,version_id,survey_start_ts,survey_question_id,start_ts,end_ts,answer > 2,registration,1,1232558018625,z1,*1232558018624*,*1232558266179*,4 > > > Answer: The timestamp is a number representing the exact date and > time. > it is the number of milliseconds since midnight, January 1, 1970. Are > you using it in the DB or R? I am not sure about R's conversion of > numbers and dates. is there a way to add a number of seconds or > milliseconds to a date in R? > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
On 22 January 2009 at 17:39, zubin wrote: | Hello, we are receiving some data, sample below - with a weird time/date | stamp format, we need some help with R on converting this time date | stamp to a useable field in R, date and time in a data-frame. The | developer says its the number of milliseconds since midnight, January 1, | 1970. | | sample: *1232558018624* | --------------------- | | | How do I interpret the time stamp? Is there a date, i need a date and time. | site_id,survey_id,version_id,survey_start_ts,survey_question_id,start_ts,end_ts,answer | 2,registration,1,1232558018625,z1,*1232558018624*,*1232558266179*,4 | | | Answer: The timestamp is a number representing the exact date and time. | it is the number of milliseconds since midnight, January 1, 1970. Are | you using it in the DB or R? I am not sure about R's conversion of | numbers and dates. is there a way to add a number of seconds or | milliseconds to a date in R? This is one of these cases where R excels once you understand what it does. Consider: > Sys.time() [1] "2009-01-22 23:23:42 UTC" > as.numeric(Sys.time()) [1] 1232666630 > Internal R representation is also a number (modulo maybe a factor of 1000 for your milliseconds) ! R represents time as seconds (incl. fractional parts) since Jan 1, 1970. All you need is do what help(as.POSIXct) suggests, after adjusting for milli-seconds (ie note the dot): > as.POSIXct(1232558018.624, origin="1970-01-01") [1] "2009-01-21 17:13:38 UTC" > Dirk -- Three out of two people have difficulties with fractions.