c# 2 timespan return yesterday
C#
const int SECOND = 1;
const int MINUTE = 60 * SECOND;
const int HOUR = 60 * MINUTE;
const int DAY = 24 * HOUR;
const int MONTH = 30 * DAY;
var ts = new TimeSpan(DateTime.UtcNow.Ticks - yourDate.Ticks);
double delta = Math.Abs(ts.TotalSeconds);
if (delta < 1 * MINUTE)
return ts.Seconds == 1 ? "one second ago" : ts.Seconds + " seconds ago";
if (delta < 2 * MINUTE)
return "a minute ago";
if (delta < 45 * MINUTE)
return ts.Minutes + " minutes ago";
if (delta < 90 * MINUTE)
return "an hour ago";
if (delta < 24 * HOUR)
return ts.Hours + " hours ago";
if (delta < 48 * HOUR)
return "yesterday";
if (delta < 30 * DAY)
return ts.Days + " days ago";
if (delta < 12 * MONTH)
{
int months = Convert.ToInt32(Math.Floor((double)ts.Days / 30));
return months <= 1 ? "one month ago" : months + " months ago";
}
else
{
int years = Convert.ToInt32(Math.Floor((double)ts.Days / 365));
return years <= 1 ? "one year ago" : years + " years ago";
}
Also in C#:
- Title
- add new page to site c# programmatically
- Category
- C#
- Title
- swith c#
- Category
- C#
- Title
- c# how to exit program
- Category
- C#
- Title
- datetitime contrusctor c#
- Category
- C#
- Title
- animator hash in unity
- Category
- C#
- Title
- sum of digits in c#
- Category
- C#
- Title
- center an image horizontally and vertically
- Category
- C#
- Title
- sort datatable c#
- Category
- C#
- Title
- c# instantiate
- Category
- C#
- Title
- How to get number of months between 2 dates c#
- Category
- C#
- Title
- c# request run as administrator
- Category
- C#
- Title
- unity button interactable
- Category
- C#
- Title
- c# window instantly close
- Category
- C#
- Title
- csharp datetime string format
- Category
- C#
- Title
- How can you learn C# on your own
- Category
- C#
- Title
- add row count devepxress report
- Category
- C#
- Title
- c# move with arrow keys
- Category
- C#
- Title
- open udp socket c#
- Category
- C#
- Title
- binding c#
- Category
- C#
- Title
- how to pause physics in unity c#
- Category
- C#
- Title
- c# getter setter
- Category
- C#
- Title
- how consider the first caracter in Split c#
- Category
- C#
- Title
- first sentence letter capital in c#
- Category
- C#
- Title
- javascript append
- Category
- C#
- Title
- c# timespan
- Category
- C#
- Title
- iformfile blobclient
- Category
- C#
- Title
- array to list C
- Category
- C#
- Title
- how to update modal class using dbfirst in asp.net core
- Category
- C#
- Title
- set decimal point c#
- Category
- C#
- Title
- c# find element in list of list
- Category
- C#
- Title
- c# dictionaries
- Category
- C#
- Title
- vb.net drag window without titlebar
- Category
- C#
- Title
- c# check to see if dictionary key exists
- Category
- C#
- Title
- epplus excel vb.net
- Category
- C#
- Title
- c# get list of all class fields
- Category
- C#
- Title
- c# get full URL of page
- Category
- C#
- Title
- c# string to lowercase
- Category
- C#
- Title
- c# uppercase string
- Category
- C#
- Title
- How to set an expiry date on a program
- Category
- C#
- Title
- while loop in c#
- Category
- C#
- Title
- c# char array to string
- Category
- C#
- Title
- override Microsoft.AspNetCore.Authorization.AuthorizeAttribute
- Category
- C#
- Title
- c# string array
- Category
- C#
- Title
- C# .net core convert string to enum
- Category
- C#
- Title
- foreach syntax c#
- Category
- C#
- Title
- how to stop a form c#
- Category
- C#
- Title
- check if number is even or odd c#
- Category
- C#
- Title
- how to detected WindowCloseEvent in other window wpf
- Category
- C#
- Title
- check which activity in focus in android
- Category
- C#
- Title
- external font family uwp c#
- Category
- C#
- Title
- c# mongodb update multiple fields
- Category
- C#
- Title
- Net.ServicePointManager.SecurityProtocol .net framework 4
- Category
- C#
- Title
- How to look at an object unity
- Category
- C#
- Title
- create object in c#
- Category
- C#
- Title
- how to cast list to observablecollection c#
- Category
- C#
- Title
- why is c# say ; expected
- Category
- C#
- Title
- unity clamp rotation
- Category
- C#
- Title
- unity image
- Category
- C#
- Title
- unity delete specific text in a string
- Category
- C#
- Title
- c# inline initialize dictionary
- Category
- C#
- Title
- if statement conditions c#
- Category
- C#
- Title
- C# random.Next error
- Category
- C#
- Title
- c sharp check if list contains
- Category
- C#
- Title
- office open xml check if row is empty
- Category
- C#
- Title
- httpcontext in .net standard
- Category
- C#
- Title
- c# make request to rest api
- Category
- C#
- Title
- c# multiple catch exceptions
- Category
- C#
- Title
- list c#
- Category
- C#
- Title
- in unity i want to destroy a gameobject when it hits the edge of the screen
- Category
- C#
- Title
- c# using get set methods
- Category
- C#
- Title
- how to edit a c# list
- Category
- C#
- Title
- linq c# or
- Category
- C#
- Title
- button color uwp c#
- Category
- C#
- Title
- c# type of generic is string
- Category
- C#
- Title
- wpf c# select folder path
- Category
- C#
- Title
- usermanager change password without current password
- Category
- C#
- Title
- c# nullable generic
- Category
- C#
- Title
- c# stop loop
- Category
- C#
- Title
- c# to binary
- Category
- C#
- Title
- how to set a transform equal to something unity
- Category
- C#
- Title
- json serialize object capitalization config
- Category
- C#
- Title
- if get key down unity
- Category
- C#
- Title
- c# distinct array of objects by values
- Category
- C#
- Title
- arry in c#
- Category
- C#
- Title
- csv to dataset c#
- Category
- C#
- Title
- query associative table ef6
- Category
- C#
- Title
- set rotation to velocity unity
- Category
- C#
- Title
- unity make a int arry with preset values
- Category
- C#
- Title
- Int64
- Category
- C#
- Title
- insert new item listview c#
- Category
- C#
- Title
- c# try catch error
- Category
- C#
- Title
- unity cast int to float
- Category
- C#
- Title
- c# properties
- Category
- C#
- Title
- c# query string builder
- Category
- C#
- Title
- unity find gameobject with layer
- Category
- C#
- Title
- create asp.net which send email and sms using own api
- Category
- C#
- Title
- c sharp split by newline
- Category
- C#
- Title
- how to go to other forms in C#
- Category
- C#
- Title
- c# udpclient receive buffer size
- Category
- C#
- Title
- how to make if statement c#
- Category
- C#