R : how to define date and time format

Nahm Lee

I have a following time stamps.

outlist "19980202_0810" "19980202_0815" "19980202_0820"

I want to have "1998-02-02T08:10:00Z" "1998-02-02T08:15:00Z" "1998-02-02T08:20:00Z"

All I can do either "1998-02-02 08:10:00 PST".

time_obj = strptime(outlist, format = "%Y%m%d_%H%M")

IRTFM

strptime is the import function; strftime is the format (output) function although I think most people would just use format:

outlist <- c("19980202_0810", "19980202_0815", "19980202_0820")
time_obj=strptime(outlist, format = "%Y%m%d_%H%M") 
format( time_obj , format="%Y-%m-%dT%H:%M:%SZ")
#[1] "1998-02-02T08:10:00Z" "1998-02-02T08:15:00Z" "1998-02-02T08:20:00Z"

At the moment these are POSIXlt items:

> class(time_obj)
[1] "POSIXlt" "POSIXt" 

It would be safer to convert to POSIXct:

> time_obj=as.POSIXct(outlist, format = "%Y%m%d_%H%M")
> time_obj
[1] "1998-02-02 08:10:00 PST" "1998-02-02 08:15:00 PST" "1998-02-02 08:20:00 PST"
> class(time_obj)
[1] "POSIXct" "POSIXt" 

POSIXlt objects are not handled well in data.frames.

Edit: The print method for POSIXct objects is documented in ?DateTimeClasses and the help page for format.POSIXct is at``srtftime` which I already cited:

strftime(time_obj, tz = "UTC")
[1] "1998-02-02 16:10:00" "1998-02-02 16:15:00" "1998-02-02 16:20:00"

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How to Define date format from a given date

分類Dev

How to change Date/Time format to English?

分類Dev

How to get current date time format in SQlite?

分類Dev

How to change date-time format?

分類Dev

How can I format date_space_hour to a time format

分類Dev

How to define a Date for run-time parameters in SQL

分類Dev

how to convert python time.time() to date format for sql insertion

分類Dev

How to format the given time string and convert to date/time object

分類Dev

What is this date and time format?

分類Dev

How to format the value of input[time] when bound to Date()-object

分類Dev

How do I get the current date and time in the format given Below

分類Dev

How to change the date/time format to English from the command line?

分類Dev

Convert Date String in Format "Mon Day, Year Time am/pm" to POSIXlt format in R?

分類Dev

Parse Date and Time in specific format

分類Dev

Convert GMT date format to only time format

分類Dev

How can I convert date time format string used by C# to the format used by moment.js?

分類Dev

pandas date-time format VS google sheets date format

分類Dev

How to format a Date with Luxon?

分類Dev

How to format this date?

分類Dev

how to define the lastest time of publication for a time series

分類Dev

Converting particular date format in R

分類Dev

Karati Api - Validating date and time format

分類Dev

Inconsistent date time format for German locale

分類Dev

Convert miliseconds to date and time and format by locale

分類Dev

format a time series as dataframe with julian date

分類Dev

convert text string to date/time format

分類Dev

PHP - Convert this string to another date/time format

分類Dev

Formatter in DateTimeFormatter for ISO 8601 date format of the time

分類Dev

What is this date time format? How to convert it into a human readable output? Why it returns this output?

Related 関連記事

  1. 1

    How to Define date format from a given date

  2. 2

    How to change Date/Time format to English?

  3. 3

    How to get current date time format in SQlite?

  4. 4

    How to change date-time format?

  5. 5

    How can I format date_space_hour to a time format

  6. 6

    How to define a Date for run-time parameters in SQL

  7. 7

    how to convert python time.time() to date format for sql insertion

  8. 8

    How to format the given time string and convert to date/time object

  9. 9

    What is this date and time format?

  10. 10

    How to format the value of input[time] when bound to Date()-object

  11. 11

    How do I get the current date and time in the format given Below

  12. 12

    How to change the date/time format to English from the command line?

  13. 13

    Convert Date String in Format "Mon Day, Year Time am/pm" to POSIXlt format in R?

  14. 14

    Parse Date and Time in specific format

  15. 15

    Convert GMT date format to only time format

  16. 16

    How can I convert date time format string used by C# to the format used by moment.js?

  17. 17

    pandas date-time format VS google sheets date format

  18. 18

    How to format a Date with Luxon?

  19. 19

    How to format this date?

  20. 20

    how to define the lastest time of publication for a time series

  21. 21

    Converting particular date format in R

  22. 22

    Karati Api - Validating date and time format

  23. 23

    Inconsistent date time format for German locale

  24. 24

    Convert miliseconds to date and time and format by locale

  25. 25

    format a time series as dataframe with julian date

  26. 26

    convert text string to date/time format

  27. 27

    PHP - Convert this string to another date/time format

  28. 28

    Formatter in DateTimeFormatter for ISO 8601 date format of the time

  29. 29

    What is this date time format? How to convert it into a human readable output? Why it returns this output?

ホットタグ

アーカイブ