Giter Site home page Giter Site logo

Comments (5)

eddelbuettel avatar eddelbuettel commented on June 2, 2024

I do not follow. Is your request about the different between the time and date parsers? Can you show an input element or two?

If you are concerned how a date, when parsed as a time, get the local timezone added then you can use the tz arguments.

> library(anytime)
> anytime("2021-07-16")
[1] "2021-07-16 EDT"                                 
> anydate("2021-07-16")
[1] "2021-07-16"
> utcdate("2021-07-16")
[1] "2021-07-16"
> utctime("2021-07-16")
[1] "2021-07-15 20:00:00 EDT"
> Sys.getenv("TZ")
[1] ""
> 

(This is in a machine without explicit TZ but currently in Eastern Daylight Time.)

Note that the printed display is done by R itself for the object we create, either a Date or a POSIXct and prints the latter with, and the former without, a timezone display. But that is just pretty-printing and has no influence on parsing.

from anytime.

eddelbuettel avatar eddelbuettel commented on June 2, 2024

Also:

> tt <- anytime("2021-07-16 10:11:12")
> class(tt)
[1] "POSIXct" "POSIXt" 
> format(tt)
[1] "2021-07-16 10:11:12"
> print(tt)
[1] "2021-07-16 10:11:12 EDT"
> 

So if instead of relying on the default print() method you override your own, even using format(), or even just use format() to create strings, you should get what you desire.

Does that answer your question?

from anytime.

genghiskhanofnz avatar genghiskhanofnz commented on June 2, 2024

@eddelbuettel = i will try format() on Monday when I go back to work. Will get back to you on the outcome. Appreciated your time and effort in this very quick response.

from anytime.

eddelbuettel avatar eddelbuettel commented on June 2, 2024

Another one, by the way, is just to format yourself -- the parse object is a POSIXTct so you can also do:

 > now <- Sys.time()    # use your anytime() parsed object here                                                                                                                                          
 > cat("It is now", strftime(now, "%Y-%m-%d %H:%M:%S"), "and we like it without the TZ\n")                                                                    
 It is now 2021-07-16 17:25:29 and we like it without the TZ                                                                                                  
 >  

As none of this is a problem in anytime, I will close. Please feel free to reopen if you think you have an issue.

from anytime.

genghiskhanofnz avatar genghiskhanofnz commented on June 2, 2024

Thanks. I will try this @eddelbuettel

from anytime.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.