]
There is a C# background implementation available on the Internet Method, please post it below for easy viewing:)
The code is as follows:
public string DateStringFromNow(DateTime dt)
{
TimeSpan span = DateTime.Now - dt;
if (span.TotalDays >60)
{
return dt.ToShortDateString();
}
else
if ( span.TotalDays >30 )
{
return
"1 month ago";
}
else
if ( span.TotalDays >14)
{
return
"2 weeks ago";
}
else
if (span.TotalDays >7)
{
return
"1 week ago";
}
else
if (span.TotalDays >1)
{
return
string.Format("{0} days ago", (int)Math.Floor(span.TotalDays));
}
else
if (span.TotalHours >1)
{
return
string. Format("{0} hours ago", (int)Math.Floor(span.TotalHours));
}
else
if (span.TotalMinutes >1)
{
return
string.Format("{0} minutes ago", (int)Math.Floor(span.TotalMinutes));
}
else
if (span.TotalSeconds >=1)
{
return
string.Format("{0} seconds ago", (int)Math.Floor(span.TotalSeconds));
}
else
{
return
"1 second ago";
}
}
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn