kawaii5
kawaii5

Reputation: 35

Snap interface - getting the Time

I am using the Snap interface and I am wondering if there is a function ':: Request -> Time'. (Or CTime).

I would like to get the time when someone visits the webpage.

Upvotes: 1

Views: 70

Answers (1)

max taldykin
max taldykin

Reputation: 12908

Request does not have any time in it (you can check this from source).

But you can get current time while handling request:

import Data.Time.Clock (getCurrentTime)
import Data.Time.Format
import qualified Data.Text as T

someHandler :: Handler App App ()
someHandler = do
  utcTime <- liftIO getCurentTime
  writeText $ T.pack $ formatTime undefined "%F %T" utcTime

Upvotes: 3

Related Questions