Last modification date based on timezone

As of March 2020, School of Haskell has been switched to read-only mode.

So, we have to find out the last modification date of the file and display this date based on the current timezone. Timezone name must be specified in the standard three-letter form.

Solution

We have to install packages directory and time, and after that:

module Main where

import System.Directory (getModificationTime)
import Data.Time.LocalTime (getCurrentTimeZone,
                            utcToLocalTime,
                            timeZoneName)

main :: IO ()
main = do
    utcTime <- getModificationTime "/Users/dshevchenko/my.conf"
    zone <- getCurrentTimeZone
    let localTime = utcToLocalTime zone utcTime
    putStrLn $ show localTime ++ " " ++ timeZoneName zone

Result is something like this:

2014-05-18 21:53:39 MSK

That's it.