I would like to get a data format like "yyyy-mm-dd hh:mm:ss timezone" for Sys.time() as part of the "cat" function. When I use the two functions by themselves there is no problem but when I use the conversion function inside the cat function I don't get the desired data format. How can I solve this issue?
> cat("THE TIME NOW: ",as.POSIXct(Sys.time(), origin="1970-01-01"))
THE TIME NOW: 1468251677
> as.POSIXct(Sys.time(), origin="1970-01-01")
[1] "2016-07-11 18:41:21 IDT"
I guess this is what you want:
cat("THE TIME NOW: ",as.character(as.POSIXct(Sys.time(), origin="1970-01-01"),usetz=T),sep="")
Output:
THE TIME NOW: 2016-07-11 16:55:15 BST
I just had to transform the output of the function as.POSIXct(Sys.time()) to character before using cat. The parameter usetz=T tells the as.character function that you want to keep the timezone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With