Humanizer
Humanizer copied to clipboard
Time difference between DateTime.ToString() and DateTime.Humanize()?
I'm using Humanizer to show a human-readable time of posting a forum thread, like so:
<time class="date"
datetime="@Model.CreationDate.ToString("yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture)"
title="@Model.CreationDate.ToString("dd MMMM yyyy HH:mm", CultureInfo.InvariantCulture)">
@Model.CreationDate.Humanize(culture: CultureInfo.InvariantCulture)
</time>
Both .ToString()
and .Humanize()
use CultureInfo.InvariantCulture
.
My system clock right now is
and I'm in UTC+1 timezone, but the HTML output I see is
<time class="date" datetime="2021-01-06 02:09" title="06 January 2021 02:09">
49 minutes from now
</time>
so while .ToString()
displays the correct time, .Humanize()
seems to be displaying it incorrectly.
I'm also having this issue and had hoped to come here and find a solution.
<div class="contenthub-grid-item-content">
<h3 class="contenthub-grid-item-title">@Model.BlogPostTitle</h3>
<p class="contenthub-grid-item-time">@Model.PostDate.Humanize().Transform(To.SentenceCase)</p>
</div>
Model.PostDate returns Date = {5/18/2021 10:33:14 AM}
but the Humanized time is saying "40 minutes from now"
Fixed it by passing a false value to Humanize -
string timeSince = postDate.Humanize(false).Transform(To.SentenceCase);
This seems to work by not using UTC timezone.
That did the trick, thanks!
Fixed it by passing a false value to Humanize -
string timeSince = postDate.Humanize(false).Transform(To.SentenceCase);
This seems to work by not using UTC timezone.
How to set manually comparison time ?