Flicker Images

Find programmers and grapic design experts at ScriptLance.com

Wednesday, November 16, 2011

how we get current date ,month and year( C#.net)



You can get Current day, month, and year using this class


public class MY_Date
{
    /// <summary>
    /// Current Month
    /// </summary>
    public static string CurMonth = GetCurrentMonth();
        /// <summary>
        /// Current Year
        /// </summary>
        public static string CurYear =GetCurrentYear();

    /// Current Month
    /// </summary>
    public static DateTime Yesterday = GetYesterday();
        /// <summary>
        /// Current Year
        /// </summary>
    public static DateTime Tomorrow = GetTomorrow();
     
private static string GetCurrentYear()
{
DateTime dt = DateTime.Now;
            return dt.Year.ToString();
        }
private static string GetCurrentMonth()
{
DateTime dt = DateTime.Now;
            return dt.Month.ToString();
        }
/// <summary>
        /// last day of the year for today.
        /// </summary>
        static DateTime LastDayOfYear()
        {
   return LastDayOfYear(DateTime.Today);
        }

        /// <summary>
        /// last day of the year for the selected day's year.
        /// </summary>
        static DateTime LastDayOfYear(DateTime d)
        {
   // 1
   // Get first of next year
   DateTime n = new DateTime(d.Year + 1, 1, 1);
   // 2
   // Subtract 1 from it
   return n.AddDays(-1);
        }
    /// <summary>
        /// Gets the first day of the current year.
        /// </summary>
        static DateTime FirstDayOfYear()
        {
   return FirstDayOfYear(DateTime.Today);
        }

        /// <summary>
        /// Finds the first day of year of the specified day.
        /// </summary>
        static DateTime FirstDayOfYear(DateTime y)
        {
   return new DateTime(y.Year, 1, 1);
        }
   
    /// <summary>
        /// Gets the next day, tomorrow.
        /// </summary>
        private static DateTime GetTomorrow()
        {
   return DateTime.Today.AddDays(1);
        }
   /// <summary>
        /// Gets the previous day to the current day.
        /// </summary>
        private static DateTime GetYesterday()
        {
   // Add -1 to now
   return DateTime.Today.AddDays(-1);
        }

}
Share:

1 comment:

Game Reviews

BTemplates.com

Powered by Blogger.

Search This Blog

Video Of Day

Find Us OIn Facebook

Blogroll

Contact

Tackle the Web with up to 5 new .COMs, $5.99 for the 1st year!

Advertisement