Dec 12, 2013

C# String to DateTime by CurrentCulture

public static DateTime StringToDateTime(string dateAsString, string format)
        {
            DateTime dateValue;
            //System.Globalization.CultureInfo culture = System.Globalization.CultureInfo.CurrentCulture;
            CultureInfo culture = Thread.CurrentThread.CurrentCulture;
            System.Globalization.DateTimeStyles styles = System.Globalization.DateTimeStyles.None;
            if (!string.IsNullOrEmpty(format))
            {
                DateTime.TryParseExact(dateAsString, format, culture, styles, out dateValue);

            }
            else
            {
                DateTime.TryParse(dateAsString, culture, styles, out dateValue);

            }
            return dateValue;
        }
   
   
    double FSeconds=TimeSpan.Parse(DateTime.Now.TimeOfDay.ToString()).TotalSeconds;
   
    TimeSpan t = TimeSpan.FromSeconds(seconds);
   
    DateTime date=DateTime.Now.Date+t;
   

0 comments:

Post a Comment

Nam Le © 2014 - Designed by Templateism.com, Distributed By Templatelib