How to convert column from millisecond epoch time to yyyy-mm-dd GMT

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to convert column from millisecond epoch time to yyyy-mm-dd GMT

R help mailing list-2
Hello to all the smart people out there....

I have a data.frame labeled itsm_service_type_field. I need to convert the Timestamp field which is epoch time in milliseconds to a yyyy-mm-dd GMT Date. 

Data.frame format is below.

I've attempted to use the lapply and as.POSIXct functions to convert the time field in the original data.frame to a new data.frame I've labeled "itsm_service_type_field_adjusted_time",
but I've got the order and syntax wrong.

Help would be so much appreciated.

Thanks in advance.
Gregg
Arizona

Details - See Below:

itsm_service_type_field <- fread("itsm_service_type_2018-2019_CONUS.csv")

>>>>>>>>>>>>>???????????itsm_service_type_field_adjusted_time <- lapply(itsm_service_type_field[ , Timestamp], as.POSIXct(Timestamp, origin="1970-01-01", tz="GMT"))

head(itsm_service_type_field)
    Id                              Timestamp         Data Type Visibility                      TYPE_SERVICE
1: INCBR0005072277 1577059200000 itsm-ticket U&FOUO&USA            0
2: INCBR0005073034 1577059200000 itsm-ticket U&FOUO&USA            1
3: INCBR0005073131 1577059200000 itsm-ticket U&FOUO&USA            0
4: INCBR0005074186 1577059200000 itsm-ticket U&FOUO&USA            0
5: INCBR0005074188 1577059200000 itsm-ticket U&FOUO&USA            0
6: INCBR0005074546 1577059200000 itsm-ticket U&FOUO&USA            0
______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.

signature.asc (490 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How to convert column from millisecond epoch time to yyyy-mm-dd GMT

Enrico Schumann-2
On Tue, 23 Jun 2020, Gregg via R-help writes:

> Hello to all the smart people out there....
>
> I have a data.frame labeled itsm_service_type_field. I need to convert
> the Timestamp field which is epoch time in milliseconds to a
> yyyy-mm-dd GMT Date. 
>
> Data.frame format is below.
>
> I've attempted to use the lapply and as.POSIXct
> functions to convert the time field in the original
> data.frame to a new data.frame I've labeled
> "itsm_service_type_field_adjusted_time",
> but I've got the order and syntax wrong.
>
> Help would be so much appreciated.
>
> Thanks in advance.
> Gregg
> Arizona
>
> Details - See Below:
>
> itsm_service_type_field <- fread("itsm_service_type_2018-2019_CONUS.csv")
>
>>>>>>>>>>>>>>???????????itsm_service_type_field_adjusted_time <- lapply(itsm_service_type_field[ , Timestamp], as.POSIXct(Timestamp, origin="1970-01-01", tz="GMT"))
>
> head(itsm_service_type_field)
>     Id                              Timestamp         Data Type Visibility                      TYPE_SERVICE
> 1: INCBR0005072277 1577059200000 itsm-ticket U&FOUO&USA            0
> 2: INCBR0005073034 1577059200000 itsm-ticket U&FOUO&USA            1
> 3: INCBR0005073131 1577059200000 itsm-ticket U&FOUO&USA            0
> 4: INCBR0005074186 1577059200000 itsm-ticket U&FOUO&USA            0
> 5: INCBR0005074188 1577059200000 itsm-ticket U&FOUO&USA            0
> 6: INCBR0005074546 1577059200000 itsm-ticket U&FOUO&USA            0
>

You should divide by 1000:

    .POSIXct(1577059200000/1000, tz = "GMT")
    ## [1] "2019-12-23 GMT"

    as.POSIXct(1577059200000/1000,
               origin = as.POSIXct("1970-01-01 00:00:00", tz = "GMT"),
               tz = "GMT")
    ## [1] "2019-12-23 GMT"


--
Enrico Schumann
Lucerne, Switzerland
http://enricoschumann.net

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: How to convert column from millisecond epoch time to yyyy-mm-dd GMT

R help mailing list-2
In reply to this post by R help mailing list-2
When you give an example it really helps to (a) show the data as the output
of dput() or dump() so one can copy and paste into R and (b) show the
result (the wrong value or error message) that you got.

You example is missing some quotes and has an unneeded call to lapply().

> dump("Data", file=stdout())
Data <-
structure(list(Id = c("INCBR0005072277", "INCBR0005073034",
"INCBR0005073131",
"INCBR0005074186", "INCBR0005074188"), Timestamp = c(1577059200000,
1577059200000, 1577059200000, 1577059200000, 1577059200000),
    `Data Type` = c("itsm-ticket", "itsm-ticket", "itsm-ticket",
    "itsm-ticket", "itsm-ticket"), Visibility = c("U&FOUO&USA",
    "U&FOUO&USA", "U&FOUO&USA", "U&FOUO&USA", "U&FOUO&USA"),
    TYPE_SERVER = c(0L, 1L, 0L, 0L, 0L)), row.names = c(NA, -5L
), class = "data.frame")
> str(as.POSIXct(Data$Timestamp/1000,
origin=as.POSIXct("1970-01-01",tz="UTC"), tz="UTC"))
 POSIXct[1:5], format: "2019-12-23" "2019-12-23" "2019-12-23" "2019-12-23"
"2019-12-23"

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Tue, Jun 23, 2020 at 11:24 AM Gregg via R-help <[hidden email]>
wrote:

> Hello to all the smart people out there....
>
> I have a data.frame labeled itsm_service_type_field. I need to convert the
> Timestamp field which is epoch time in milliseconds to a yyyy-mm-dd GMT
> Date.
>
> Data.frame format is below.
>
> I've attempted to use the lapply and as.POSIXct functions to convert the
> time field in the original data.frame to a new data.frame I've labeled
> "itsm_service_type_field_adjusted_time",
> but I've got the order and syntax wrong.
>
> Help would be so much appreciated.
>
> Thanks in advance.
> Gregg
> Arizona
>
> Details - See Below:
>
> itsm_service_type_field <- fread("itsm_service_type_2018-2019_CONUS.csv")
>
> >>>>>>>>>>>>>???????????itsm_service_type_field_adjusted_time <-
> lapply(itsm_service_type_field[ , Timestamp], as.POSIXct(Timestamp,
> origin="1970-01-01", tz="GMT"))
>
> head(itsm_service_type_field)
>     Id                              Timestamp         Data Type
> Visibility                      TYPE_SERVICE
> 1: INCBR0005072277 1577059200000 itsm-ticket U&FOUO&USA            0
> 2: INCBR0005073034 1577059200000 itsm-ticket U&FOUO&USA            1
> 3: INCBR0005073131 1577059200000 itsm-ticket U&FOUO&USA            0
> 4: INCBR0005074186 1577059200000 itsm-ticket U&FOUO&USA            0
> 5: INCBR0005074188 1577059200000 itsm-ticket U&FOUO&USA            0
> 6: INCBR0005074546 1577059200000 itsm-ticket U&FOUO&USA
> 0______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.