Formatting a date in R without leading zeros

前端 未结 4 1602
野性不改
野性不改 2020-12-07 00:33

Is there a way to use the format function on a date object, specifically an object of class POSIXlt, POSIXct, or Date, wi

4条回答
  •  我在风中等你
    2020-12-07 00:59

    A more general solution using gsub, to remove leading zeros from the day or month digits produced by %m or %d. This deletes any zero that is not preceded by a digit:

    gsub("(\\D)0", "\\1", format(as.Date("1998-09-02"), "%Y, %m, %d"))
    

提交回复
热议问题