C# 获取时间差状态

        /// <summary>
        /// 根据时间获取时间状态
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public string GetTimeInfo(DateTime dt)
        {
            TimeSpan span = DateTime.Now - dt;
            if (span.TotalDays > 60)
            {
                return dt.ToShortDateString();
            }
            else if (span.TotalDays > 30)
            {
                return "1个月前";
            }
            else if (span.TotalDays > 14)
            {
                return "2周前";
            }
            else if (span.TotalDays > 7)
            {
                return "1周前";
            }
            else if (span.TotalDays > 1)
            {
                return string.Format("{0}天前", (int)Math.Floor(span.TotalDays));
            }
            else if (span.TotalHours > 1)
            {
                return string.Format("{0}小时前", (int)Math.Floor(span.TotalHours));
            }
            else if (span.TotalMinutes > 1)
            {
                return string.Format("{0}分钟前", (int)Math.Floor(span.TotalMinutes));
            }
            else if (span.TotalSeconds >= 1)
            {
                return string.Format("{0}秒前", (int)Math.Floor(span.TotalSeconds));
            }
            else
            {
                return "刚刚";
            }
        }记录下,防止忘记!
时间: 2024-08-28 02:44:19

C# 获取时间差状态的相关文章

Android 通过广播获取网络状态

Android系统网络连接状态的改变会发一个广播,注册一个广播接收者,实时动态的检测网络状态,及时提醒用户,优化用户体验. 本文仅提供WIFI 状态的检测作为参考,其他网络连接方式请对比WIFI连接作出调整. 首先写一个WifiStateBroadcast类继承BroadcastReceiver,重写onRecevie方法,获取网络连接状态管理器,通过管理器拿到对应的网络信息,得到网络状态,判断网络状态,作出相应的业务逻辑. 1 public class WifiStateBroadCast e

从两个TIMESTAMP中获取时间差(秒)

When you subtract two variables of type TIMESTAMP, you get an INTERVAL DAY TO SECOND which includes a number of milliseconds and/or microseconds depending on the platform. If the database is running on Windows, systimestamp will generally have millis

iOS 获取网络状态

在iOS开发者,获取网络状态比较常用 -(NSString *)getNetWorkStates{ UIApplication *app = [UIApplication sharedApplication]; NSArray *children = [[[app valueForKeyPath:@"statusBar"]valueForKeyPath:@"foregroundView"]subviews]; NSString *state = nil; int n

android开发获取网络状态,wifi,wap,2g,3g.工具类(一)

android开发获取网络状态整理: 1 package com.gzcivil.utils; 2 3 import android.content.Context; 4 import android.net.ConnectivityManager; 5 import android.net.NetworkInfo; 6 import android.telephony.TelephonyManager; 7 import android.text.TextUtils; 8 9 public c

C# 获取时间差(几天前,几小时前,几分钟前,几秒前)

1 #region 获取时间差string GetTime(BsonString getTime) 2 /// <summary> 3 /// 获取时间差 4 /// </summary> 5 /// <param name="getTime">数据库时间</param> 6 /// <returns>时间差</returns> 7 private string GetTime(BsonString getTime

StickyBroadcast在获取电池状态中的妙用

StickyBroadcast在获取电池状态中的妙用 今天在做开发的时候,突然遇到这样的一个问题,当你的设备电量低于15%的时候这个时候设备的闪光灯是无法打开的,但是我们平台的解决方案对这一块没有做出任何的提示,于是直接导致了用户认为他的闪光灯坏掉了,于是老大要求我们解决这个问题. 我们都知道电池的电量信息获取我们是通过广播来实现的. 标准做法如下: private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {

获取网络状态,区分2G3G4GWIFI等,非reachability

+(NSString *)getNetWorkStates{ UIApplication *app = [UIApplication sharedApplication]; NSArray *children = [[[app valueForKeyPath:@"statusBar"]valueForKeyPath:@"foregroundView"]subviews];    NSString *state = [[NSString alloc]init];   

PS脚本获取网络适配器状态

1. Get-WmiObject -Class Win32_NetworkAdapterConfiguration ` -filter "IPEnabled = $true" 2. Get-WmiObject -Class Win32_NetworkAdapter | Format-Table -Property Name, NetConnectionStatus -AutoSize 3.netsh interface show interface PS脚本获取网络适配器状态

Android获取手机状态和监听手机来电状态

获取手机状态: import android.content.Context; import android.telephony.TelephonyManager; //获得相应的系统服务 TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); /** * 返回电话状态 * * CALL_STATE_IDLE 无任何状态时 * CALL_STATE_OFFHOOK 接起电话时 *