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

本文提供了一个简单的C#代码示例,用于处理手机号码中的敏感信息,并计算两个时间戳之间的差异,返回易读的时间单位。
  /// <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

 

转载于:https://www.cnblogs.com/xyzhuzhou/archive/2012/05/15/2500990.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值