Jan 18, 2013

string to DateTime as CurrentCulture

public static DateTime StringToDateTime(string dateAsString,string format)
    {
        DateTime dateValue;
        System.Globalization.CultureInfo culture = System.Globalization.CultureInfo.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