Gets First day of Month - CSharp System

CSharp examples for System:DateTime Day

Description

Gets First day 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;//from   w w w .j  a  va 2s.  c om

public class Main{
        /// <summary>
        /// Gets First day of Month
        /// </summary>
        /// <param name="date">The date.</param>
        /// <returns></returns>
        public static long FirstDayOfMonth(this DateTime date)
        {
            return new DateTime(date.Year, date.Month, 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