Reputation: 687
Why does this work,
@string.Format("{0:hh:mm:ss tt}", DateTime.Now)
But not this?
@string.Format("{0:hh:mm:ss tt}", worker.BegginingTime)
worker.BegginingTime
is a TimeSpan (edited due to comments) received from the database not a date.
How would I format just a TimeSpan correctly with am or pm?
Upvotes: 0
Views: 1128
Reputation: 70307
You'll need to convert it into a DateTime or write a custom formatter.
@string.Format("{0:hh:mm:ss tt}", new DateTime().Add(worker.BegginingTime))
Technically speaking TimeSpan doesn't store time of day, but rather duration.
Upvotes: 3