C # shows how long a function has been in the past

Source: Internet
Author: User
C # shows how long a function has been in the past

public string Howlongbeforenow {get {var ts = new TimeSpan (datetime.utcnow.t                Icks-createddate.ticks); var delta = ts.                TotalSeconds;                const int second = 1;                const int minute = * SECOND;                const int hour = * MINUTE;                const INT day = * HOUR;                const INT month = * DAY; if (Delta < 0) {throw new Invaliddataexception ("The createddate can not be gather th                An today. "); if (Delta < 1 * minute) {return TS. Seconds = = 1? "1 second ago": TS.                Seconds + "Seconds ago";                } if (Delta < 2 * minute) {return "1 minute ago"; } if (Delta < * minute) {return TS.                Minutes + "Minutes ago";           }     if (Delta < * minute) {return "1 hour ago"; } if (Delta < * hour) {return TS.                Hours + "Hours ago";                } if (Delta < * hour) {return "Yesterday"; } if (Delta < * day) {return TS.                Days + ' days ago '; } if (Delta < month) {var months = Convert.ToInt32 (Math.floor (d ouble) Ts.                    DAYS/30)); Return months <= 1?                "1 month ago": Months + "months ago"; } var years = Convert.ToInt32 (Math.floor (double) ts.                days/365)); Return years <= 1?            "1 year ago": Years + "years ago"; }        }

Css:

. how-long-ago {        font-style:italic;        Color: #777;    }


These are the contents of the function that C # shows in the past, and more about topic.alibabacloud.com (www.php.cn)!

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.