Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8770873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:38:49+00:00 2026-06-13T17:38:49+00:00

I have a problem converting POSIXct to character and back in POSIXct in R.

  • 0

I have a problem converting POSIXct to character and back in POSIXct in R. I run the following code:

time_seq_01 <- seq(as.POSIXct("2012-10-28 02:00:00"), by = 900, length.out = 10)
time_seq_02 <- as.character(time_seq_01)
time_seq_03 <- as.POSIXct(time_seq_02)

or equivalent:

time_seq_01 <- seq(as.POSIXct("2012-10-28 02:00:00"), by = 900, length.out = 10)
time_seq_02 <- format(time_seq_01,usetz = TRUE)
time_seq_03 <- as.POSIXct(time_seq_02)

This are the timestamps in 2012 when the daylight saving transition from Central European Summer Time (CEST) to Central European Time (CET) occurs (Last Sunday in October 02:00 – 03:00).

When I call these elements I get

time_seq_01
[1] "2012-10-28 02:00:00 CEST" "2012-10-28 02:15:00 CEST"
[3] "2012-10-28 02:30:00 CEST" "2012-10-28 02:45:00 CEST"
[5] "2012-10-28 02:00:00 CET"  "2012-10-28 02:15:00 CET" 
[7] "2012-10-28 02:30:00 CET"  "2012-10-28 02:45:00 CET" 
[9] "2012-10-28 03:00:00 CET"  "2012-10-28 03:15:00 CET" 
time_seq_02
[1] "2012-10-28 02:00:00 CEST" "2012-10-28 02:15:00 CEST"
[3] "2012-10-28 02:30:00 CEST" "2012-10-28 02:45:00 CEST"
[5] "2012-10-28 02:00:00 CET"  "2012-10-28 02:15:00 CET" 
[7] "2012-10-28 02:30:00 CET"  "2012-10-28 02:45:00 CET" 
[9] "2012-10-28 03:00:00 CET"  "2012-10-28 03:15:00 CET" 
time_seq_03
[1] "2012-10-28 02:00:00 CEST" "2012-10-28 02:15:00 CEST"
[3] "2012-10-28 02:30:00 CEST" "2012-10-28 02:45:00 CET" 
[5] "2012-10-28 02:00:00 CEST" "2012-10-28 02:15:00 CEST"
[7] "2012-10-28 02:30:00 CEST" "2012-10-28 02:45:00 CET" 
[9] "2012-10-28 03:00:00 CET"  "2012-10-28 03:15:00 CET" 

The creation of a POSIXct sequence does work correctly (time_seq_01) the transition to character also (time_seq_02). However the transition back from character back to POSIXct produces wrong timezone (CET/CEST) values (time_seq_03). This can be clearly seen when those elements are sorted:

sort(time_seq_01)
[1] "2012-10-28 02:00:00 CEST" "2012-10-28 02:15:00 CEST"
[3] "2012-10-28 02:30:00 CEST" "2012-10-28 02:45:00 CEST"
[5] "2012-10-28 02:00:00 CET"  "2012-10-28 02:15:00 CET" 
[7] "2012-10-28 02:30:00 CET"  "2012-10-28 02:45:00 CET" 
[9] "2012-10-28 03:00:00 CET"  "2012-10-28 03:15:00 CET" 
sort(time_seq_03)
[1] "2012-10-28 02:00:00 CEST" "2012-10-28 02:00:00 CEST"
[3] "2012-10-28 02:15:00 CEST" "2012-10-28 02:15:00 CEST"
[5] "2012-10-28 02:30:00 CEST" "2012-10-28 02:30:00 CEST"
[7] "2012-10-28 02:45:00 CET"  "2012-10-28 02:45:00 CET" 
[9] "2012-10-28 03:00:00 CET"  "2012-10-28 03:15:00 CET" 

This causes a number of problems for instance when merging objects by those timestamps. Is there a way to overcome this problem?

The system I use:

Windows 7 64bit
R version 2.15.1 (2012-06-22)
Platform: x86_64-pc-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=German_Austria.1252  LC_CTYPE=German_Austria.1252   
[3] LC_MONETARY=German_Austria.1252 LC_NUMERIC=C                   
[5] LC_TIME=German_Austria.1252    
attached base packages:
[1] tools     stats     graphics  grDevices utils     datasets  methods 
[8] base     
other attached packages:
[1] pkgtools_0.1-3 roxygen2_2.2.2 digest_0.5.2   rj_1.1.0-4    
loaded via a namespace (and not attached):
[1] brew_1.0-6    plyr_1.7.1    rj.gd_1.1.0-1 stringr_0.6.1
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T17:38:50+00:00Added an answer on June 13, 2026 at 5:38 pm

    Here’s a work around that goes from POSIXct to character back to POSIXct preserving the original daylight savings time status.

    Sys.setenv(TZ='Europe/Berlin') # to reproduce OP's example
    time_seq_01 <- seq(as.POSIXct("2012-10-28 02:00:00"), by = 900, length.out = 10)
    time_seq_02 <- format(time_seq_01,usetz = TRUE)
    
    time_seq_02_lt <- as.POSIXlt(time_seq_02)
    time_seq_02_lt$isdst <- as.POSIXlt(time_seq_01)$isdst
    time_seq_03 <- as.POSIXct(time_seq_02_lt)
    

    As far as I can tell, R’s support for string-to-datetime doesn’t include DST flags specified within the strings.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this problem converting java.sql.Timestamp.toString back to java.sql.Timestamp . Given element = 2012-08-01
I have a problem converting a 32-bit to 64-bit code using the lsaapi.pas unit
Is there any particular problem in converting these kind of code into VS2010(I have
I have a problem in my code and I figure it out: SELECT pono,
Possible Duplicate: converting C to C# i have problem in converting by c code
I have run in to this problem of converting a C++/CLI pointer to a
I have a problem converting a string binary to a decimal I was using
I have a problem while converting a string whose value is dd.mm.yyyy to DateTime
I have a weird problem in converting a string to double in .NET 3.5.
I seem to have a problem converting an array backwards and forwards between PHP/JS.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.