• 计算用户的在线时间


      今天要计算用户在线的时间, 时间的格式:  2014-07-09 15:27:38

      写了一个静态方法, 输入两个时间,可以得到两个时间差.

      

     1 static class time
     2     {
     3         static string reg_d="(?<=(\-))\d+";
     4         static string reg_h="\d+(?=\:)";
     5         static int[] monthdays_p={0,0,131,59,90,120,151,181,212,243,273,304,334};
     6         //static int monthdays_r[]={0,0,131,59,90,120,151,181,212,243,273,304,334};
     7        public  static int cha(string a,string b)
     8         {
     9             int am=0,ad=0,ah=0,af=0;
    10             int bm=0,bd=0,bh=0,bf=0;
    11             int i=0;
    12             foreach(Match m in Regex.Matches(a,reg_d))
    13             {
    14                 if(i++==0)
    15                     am=int.Parse(m.ToString());
    16                 ad=int.Parse(m.ToString());
    17             }
    18             i=0;
    19             foreach(Match m in Regex.Matches(b,reg_d))
    20             {
    21                 if(i++==0)
    22                     bm=int.Parse(m.ToString());
    23                 bd=int.Parse(m.ToString());
    24             }
    25             i=0;
    26             foreach(Match m in Regex.Matches(a,reg_h))
    27             {
    28                 if(i++==0)
    29                     ah=int.Parse(m.ToString());
    30                 af=int.Parse(m.ToString());
    31             }
    32             i=0;
    33             foreach(Match m in Regex.Matches(b,reg_h))
    34             {
    35                 if(i++==0)
    36                     bh=int.Parse(m.ToString());
    37                 bf=int.Parse(m.ToString());
    38             }
    39 
    40             int chazhi=0;
    41 
    42             chazhi=bf-af+(bh-ah)*60+(bd-ad+monthdays_p[bm]-monthdays_p[am])*1440;
    43             return chazhi;
    44         }
    45     }
  • 相关阅读:
    PopupWindow设置动画效果
    android判断是否含有某权限
    每日一更提醒
    利用Pattern和Mather来禁止特殊字符的输入
    Android毛玻璃处理代码(Blur)
    how to render html tag
    数组
    复杂度分析
    书写markdown的利器
    cannot insert multiple commands into a prepared statement问题原因及解决办法
  • 原文地址:https://www.cnblogs.com/Fadinglemon/p/3838527.html
Copyright © 2020-2023  润新知