sheikh-k
11/3/2016 - 2:50 PM

DateUtil (dRetail).cs

using System;

namespace dRetail.Common
{
    public static class DateUtil
    {
        public static DateTime FormatDate(DateTime dateTime, string format)
        {
            return DateTime.Parse(dateTime.ToString(format));
        }

        public static string FormatDateToString(DateTime dateTime, string format)
        {
            return dateTime.ToString(format);
        }

        public static DateTime StringToDate(string dateTime)
        {
            return DateTime.Parse(dateTime);
        }

        public static string StringDateTimeNow()
        {
            var dateTime = DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day + " " + DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second;
            return dateTime;
        }

        public static string StringDateNow()
        {
            var dateTime = DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year;
            return dateTime;
        }

        public static string DateTimeToStringDateTime(DateTime dt)
        {
            var dateTime = dt.Year + "-" + dt.Month + "-" + dt.Day + " " + dt.Hour + ":" + dt.Minute + ":" + dt.Second;
            return dateTime;
        }

        public static DateTime GetDateTimeNow()
        {
            var dateTime = DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day + " " + DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second;
            return StringToDate(dateTime);
        }

    }
}