public static string DateDiff(DateTime DateTime1, DateTime DateTime2) { string dateDiff = null; try { //TimeSpan ts1 = new TimeSpan(DateTime1.Ticks); //TimeSpan ts2 = new TimeSpan(DateTime2.Ticks); //TimeSpan ts = ts1.Subtract(ts2).Duration(); TimeSpan ts = DateTime2 - DateTime1; if (ts.Days >= 1) { dateDiff = DateTime1.Month.ToString() + "月" + DateTime1.Day.ToString() + "日"; } else { if (ts.Hours > 1) { dateDiff = ts.Hours.ToString() + "小时前"; } else { dateDiff = ts.Minutes.ToString() + "分钟前"; } } } catch (Exception e) { ShowException.ShowtheException("TimeError", e); } return(dateDiff); }
protected string Read_Txt(string filename) { Encoding code = Encoding.GetEncoding("gb2312"); string temp = HttpContext.Current.Server.MapPath("Precious\\" + filename + ".txt"); string str = ""; if (File.Exists(temp)) { StreamReader sr = null; try { sr = new StreamReader(temp, code); str = sr.ReadToEnd(); // 读取文件 } catch (Exception e) { ShowException.ShowtheException("FileError", e); } sr.Close(); sr.Dispose(); } else { str = ""; } return(str); }
/// <summary> /// 得到AppSettings中的配置字符串信息 /// </summary> /// <param name="key"></param> /// <returns></returns> public static string GetConfigString(string key) { string CacheKey = "AppSettings-" + key; object objModel = null; try { objModel = ConfigurationManager.AppSettings[key]; } catch (Exception e) { ShowException.ShowtheException("ConfigError", e); } return(objModel.ToString()); }
/// <summary> /// 得到AppSettings中的配置Bool信息 /// </summary> /// <param name="key"></param> /// <returns></returns> public static bool GetConfigBool(string key) { bool result = false; string cfgVal = GetConfigString(key); if (null != cfgVal && string.Empty != cfgVal) { try { result = bool.Parse(cfgVal); } catch (FormatException e) { ShowException.ShowtheException("ConfigError", e); } } return(result); }
/// <summary> /// 得到AppSettings中的配置int信息 /// </summary> /// <param name="key"></param> /// <returns></returns> public static int GetConfigInt(string key) { int result = 0; string cfgVal = GetConfigString(key); if (null != cfgVal && string.Empty != cfgVal) { try { result = int.Parse(cfgVal); } catch (FormatException e) { ShowException.ShowtheException("ConfigError", e); } } return(result); }
/// <summary> /// 得到AppSettings中的配置Decimal信息 /// </summary> /// <param name="key"></param> /// <returns></returns> public static decimal GetConfigDecimal(string key) { decimal result = 0; string cfgVal = GetConfigString(key); if (null != cfgVal && string.Empty != cfgVal) { try { result = decimal.Parse(cfgVal); } catch (FormatException e) { ShowException.ShowtheException("ConfigError", e); } } return(result); }
protected void Write_Txt(string FileName, string Content) { Encoding code = Encoding.GetEncoding("gb2312"); string htmlfilename = HttpContext.Current.Server.MapPath("Precious\\" + FileName + ".txt"); //保存文件的路径 string str = Content; StreamWriter sw = null; { try { sw = new StreamWriter(htmlfilename, false, code); sw.Write(str); sw.Flush(); } catch (Exception e) { ShowException.ShowtheException("FileError", e); } } sw.Close(); sw.Dispose(); }