Gets Start time of Month - CSharp System

CSharp examples for System:DateTime Month

Description

Gets Start time of Month

Demo Code


using System.Web;
using System.Text.RegularExpressions;
using System.Globalization;
using System.Extensions;
using System.Web.Mvc;
using System.Threading.Tasks;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Collections;
using System;/* w  ww .j a  va2  s.  c o m*/

public class Main{
        /// <summary>
        /// Gets Start time of Month
        /// </summary>
        /// <param name="date">The date.</param>
        /// <returns></returns>
        public static long StartTimeOfYear(this DateTime date)
        {
            return new DateTime(date.Year, 1, 1, 0, 0, 0).ToUnixTimestamp();
        }
        #endregion


        /// <summary>
        /// Converts a System.DateTime object to Unix timestamp
        /// </summary>
        /// <param name="date">The date.</param>
        /// <returns>
        /// The Unix timestamp
        /// </returns>
        public static long ToUnixTimestamp(this DateTime date)
        {
            DateTime unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0);
            TimeSpan unixTimeSpan = date - unixEpoch;

            return (long)unixTimeSpan.TotalSeconds;
        }
}

Related Tutorials