turtle icon indicating copy to clipboard operation
turtle copied to clipboard

Formatted date

Open donat-b opened this issue 7 years ago • 5 comments

What is the preferred way to get formatted date (e.g. date +%F in shell)? Thanks.

donat-b avatar Jun 06 '17 20:06 donat-b

turtle provides some default date/time formatting with the Turtle.Format.utc format specifier. Here's an example of how you could use it:

{-# LANGUAGE OverloadedStrings #-}

import Turtle

main :: IO ()
main = do
    d <- date
    printf (utc%"\n") d

That formats the date using the following format which just uses the default Show implementation for UTCTime

2017-06-07 17:14:33.278543 UTC

If you have other date/time formats in mind that you'd like turtle to support just let me know

Gabriella439 avatar Jun 07 '17 17:06 Gabriella439

Hmm, how about ISO 8601? I'm mostly interested in YYYY-MM-DDThh:mm:ss representation.

donat-b avatar Jun 07 '17 19:06 donat-b

Technically that is an ISO 8601-compliant format.

3noch avatar Jun 07 '17 19:06 3noch

Well, yeah. But I think it makes sense to add more atomic control over format, for instance, showing just date or time.

donat-b avatar Jun 07 '17 19:06 donat-b

So I can provide an iso8601 format specifier to make the date-time format explicit, but I think for anything more complex than that you should use the Data.Time.Format module directly:

https://hackage.haskell.org/package/time-1.8.0.2/docs/Data-Time-Format.html

Gabriella439 avatar Jun 12 '17 04:06 Gabriella439