手机号码部分以*代替、获取时间差和设置网页桌面图标整理

  /// <summary>
    /// 屏蔽部分手机号码以*代替
    /// </summary>
    /// <param name="_phone"></param>
    /// <returns></returns>
    public static string StuffPhone(string _phone)
    {
        string result = string.Empty;
        if (_phone.Length == 11)
        {
            result = _phone.Insert(3, "****").Remove(7, 4);
        }
        else
        {
            result = "暂无手机号码";
        }
        return result;
    }
    /// <summary>
    /// 获取时间差
    /// </summary>
    /// <param name="strTime"></param>
    /// <returns></returns>
    public static string GetTimeDiff(object strTime)
    {
        TimeSpan nowTime = new TimeSpan(DateTime.Now.Ticks);
        TimeSpan passTime = new TimeSpan(Convert.ToDateTime(strTime).Ticks);
        TimeSpan ts = nowTime.Subtract(passTime);
        if (ts.TotalDays >= 1)
        {
            return ((int)ts.TotalDays) + "天前";
        }
        if (ts.TotalHours >=1 && ts.TotalHours < 24)
        {
            return ((int)ts.TotalHours) + "小时前";
        }
        if (ts.TotalMinutes >=1 && ts.TotalMinutes < 60)
        {
            return ((int)ts.TotalMinutes) + "分钟前";
        }
        if (ts.TotalSeconds >= 1 && ts.TotalSeconds < 60)
        {
            return ((int)ts.TotalSeconds) + "秒前";
        }
        return "未知";
    }

    #region 添加网页桌面图标
    public static void AddDesktopLink(System.Web.UI.Page MyPage,string title,string url)
    {
        MyPage.Response.Clear();
        MyPage.Response.ContentType = "APPLICATION/OCTET-STREAM";
        //解决中文乱码
        MyPage.Response.Buffer = true;
        MyPage.Response.Charset = "utf-8";
        MyPage.Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
        MyPage.Response.AppendHeader("content-disposition", "attachment;filename=\"" + System.Web.HttpUtility.UrlEncode(title, System.Text.Encoding.UTF8) + ".url\"");

        MyPage.Response.Write("[InternetShortcut] \r\n");
        MyPage.Response.Write("URL= " + url + " \r\n");   //链接   
        MyPage.Response.Write("IDList= \r\n");
        //MyPage.Response.Write("IconFile= http://www.baidu.com/favicon.ico \r\n");       //图标文件   
        //MyPage.Response.Write("IconFile= http://localhost:8016/favicon.ico \r\n");       //图标文件
        MyPage.Response.Write("IconIndex=1 \r\n");
        MyPage.Response.Write("[{000214A0-0000-0000-C000-000000000046}] \r\n");
        MyPage.Response.Write("Prop3=19,2 \r\n");
        MyPage.Response.End();
    }
    #endregion

 

posted @ 2012-05-15 10:04  xyzhuzhou  阅读(399)  评论(0编辑  收藏  举报