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

  • SEARCH
  • Home
  • 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 6469109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T05:57:12+00:00 2026-05-25T05:57:12+00:00

I’m doing some extracting of data from a database, and running the results through

  • 0

I’m doing some extracting of data from a database, and running the results through rehsape2. For some reason this is mangling the POSIXct datetime stamps into numeric. No Problem I think, you can just turn them back, except I’m an hour out.

Here’s a minimal example

foo<-as.POSIXct("2011-04-04 14:18:58")
as.numeric(foo)     #gives 130192318
bar<-as.POSIXct(as.numeric(foo), 
                tz=Sys.timezone(),
                origin=as.POSIXct(
                  strptime("1970-01-01 00:00:00", "%Y-%m-%d %H:%M:%S", tz="UTC")))
as.numeric(bar)     #gives 130192318 identical !
foo     #Gives "2011-04-04 14:18:58 BST"
bar     #Gives "2011-04-04 13:18:58 UTC"

Obviously foo and bar are numerically identical, but R thinks foo needs to be displayed as BST and bar as UTC. How do I get both displayed as BST. This doesn’t work either;

as.POSIXct(bar, tz="BST")   #still gives "2011-04-04 13:18:58 UTC"
  • 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-05-25T05:57:12+00:00Added an answer on May 25, 2026 at 5:57 am

    Here’s what’s going on. bar is created using as.POSIXct.numeric, which is defined as:

    as.POSIXct.numeric
    function (x, tz = "", origin, ...) 
    {
        if (missing(origin)) 
            stop("'origin' must be supplied")
        as.POSIXct(origin, tz = tz, ...) + x
    }
    <environment: namespace:base>
    

    You supply an origin that is a POSIXct object. That means the as.POSIXct call in as.POSIXct.numeric dispatches to as.POSIXct.default, which is defined as:

    as.POSIXct.default
    function (x, tz = "", ...) 
    {
        if (inherits(x, "POSIXct")) 
            return(x)
        if (is.character(x) || is.factor(x)) 
            return(as.POSIXct(as.POSIXlt(x, tz, ...), tz, ...))
        if (is.logical(x) && all(is.na(x))) 
            return(.POSIXct(as.numeric(x)))
        stop(gettextf("do not know how to convert '%s' to class \"POSIXct\"", 
            deparse(substitute(x))))
    }
    <environment: namespace:base>
    

    x is a POSIXct class object (the origin you supplied in your initial call), so it is simply returned and the tz= argument is ignored.


    UPDATE:
    Here’s how you can convert foo back to POSIXct with the appropriate time zone.

    (foo <- as.POSIXct("2011-04-04 14:18:58", tz="GB"))
    # [1] "2011-04-04 14:18:58 BST"
    .POSIXct(as.numeric(foo), tz="GB")
    # [1] "2011-04-04 14:18:58 BST"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.