TimeSpan时间间隔
一个TimeSpan对象都表示一个时间间隔 (持续时间的时间或时间),
单位为正数或负数的天数、 小时、 分钟、 秒和小数部分的第二个数字。
TimeSpan结构还可以用于表示一天时间,但仅,如果与某一特定日期无关的时间。
否则为DateTime或DateTimeOffset应改为使用结构。
TimeSpan构造函数
1.TimeSpan(Int64): 将TimeSpan结构的新实例初始化为指定的刻度数。
2.TimeSpan(Int32, Int32, Int32): 将TimeSpan结构的新实例初始化为指定的小时数、分钟数和秒数。
3.TimeSpan(Int32, Int32, Int32, Int32): 将TimeSpan结构的新实例初始化为指定的天数、小时数、分钟数和秒数。
4.TimeSpan(Int32, Int32, Int32, Int32, Int32): 将TimeSpan结构的新实例初始化为指定的天数、小时数、分钟数、秒数和毫秒数。
1.TimeSpan(Int64),public TimeSpan (long ticks);
将TimeSpan 结构的新实例初始化为指定的刻度数
ticks 100 毫微秒为单位表示的时间段。
TimeSpan inverval2 = new TimeSpan();
Console.WriteLine(inverval2.ToString());//00:00:00.0000020
2.TimeSpan(Int32, Int32, Int32),public TimeSpan (int hours, int minutes, int seconds);
将TimeSpan 结构的新实例初始化为指定的小时数、分钟数和秒数。
TimeSpan inverval3 = new TimeSpan(, , );
Console.WriteLine(inverval3.ToString());//15:45:30
3.TimeSpan(Int32, Int32, Int32, Int32),public TimeSpan(int days, int hours, int minutes, int seconds);
将TimeSpan 结构的新实例初始化为指定的天数、小时数、分钟数和秒数。
TimeSpan inverval4_1 = new TimeSpan(, , , );
TimeSpan inverval4_2 = new TimeSpan(-, , , );
TimeSpan inverval4_3 = new TimeSpan(-, -, -, -);
TimeSpan inverval4_4 = new TimeSpan(, , , );
Console.WriteLine("{0,-35}{1,20}", "new TimeSpan(10, 20, 30, 40)", inverval4_1.ToString());
Console.WriteLine("{0,-35}{1,20}", "new TimeSpan(-10, 20, 30, 40)", inverval4_2.ToString());
Console.WriteLine("{0,-35}{1,20}", "new TimeSpan(-10, -20, -30, -40)", inverval4_3.ToString());
Console.WriteLine("{0,-35}{1,20}", "new TimeSpan(0, 49, 30, 40)", inverval4_4.ToString()); new TimeSpan(, , , ) //10.20:30:40
new TimeSpan(-, , , ) //-9.03:29:20
new TimeSpan(-, -, -, -) //-10.20:30:40
new TimeSpan(, , , ) //2.01:30:40
4.TimeSpan(Int32, Int32, Int32, Int32, Int32),public TimeSpan(int days, int hours, int minutes, int seconds, int milliseconds);
将TimeSpan 结构的新实例初始化为指定的天数、小时数、分钟数和秒数。
TimeSpan inverval5 = new TimeSpan(, , , ,);
Console.WriteLine("{0,-35}{1,20}", "new TimeSpan(10, 20, 30, 40,20)", inverval5.ToString());
new TimeSpan(, , , ,) //10.20:30:40.0200000
TimeSpan 字段
Maximum:表示最大的TimeSpan值,此字段为只读,此字段的值等效于Int64.MaxValue计时周期数。
此值的字符串表示形式是正 10675199.02:48:05.4775807 或略微超过 10675199 天。
Maximum:表示最小的TimeSpan值,此字段为只读,此字段的值等效于Int64.MinValue计时周期数。
此值的字符串表示形式是负 10675199.02:48:05.4775808 或负略微超过 10675199 天。
Zero:表示零TimeSpan值,此字段为只读
因为的值Zero字段是TimeSpan对象,表示零个时间值,将其与其他进行比较TimeSpan对象以确定
是否后者表示正的非零或负时间间隔。 此外可以使用此字段来初始化TimeSpan为零个时间值的对象。
TicksPerDay:表示一天中的刻度数。 此字段为常数。此常量的值是 864 亿个;也就是说,864,000,000,000。
TicksPerHour:表示 1 小时的刻度数。 此字段为常数。此常量的值是 36 亿个;也就是说,36,000,000,000。
icksPerMinute:表示 1 分钟的刻度数。 此字段为常数。此常量的值为 600 万;也就是说,600000000。
TicksPerSecond:表示 1 秒的刻度数。此常量的值为 1000 万;也就是说,10,000,000。
TicksPerMinute:表示 1 分钟的刻度数。 此字段为常数。此常量的值为 600 万;也就是说,600000000。
TicksPerMillisecond:表示 1 毫秒的刻度数。 此字段为常数。此常量的值是 1 万。它是 10,000。
const string numberFmt = "{0,-22}{1,18:N0}";
const string timeFmt = "{0,-22}{1,26}";
Console.WriteLine("This example of the fields of the TimeSpan class" + "\ngenerates the following output.\n");
Console.WriteLine(numberFmt, "Field", "Value");
Console.WriteLine(numberFmt, "-----", "-----");
// Display the maximum, minimum, and zero TimeSpan values.
Console.WriteLine(timeFmt, "Maximum TimeSpan", Align(TimeSpan.MaxValue));
Console.WriteLine(timeFmt, "Minimum TimeSpan", Align(TimeSpan.MinValue));
Console.WriteLine(timeFmt, "Zero TimeSpan", Align(TimeSpan.Zero));
Console.WriteLine();
// Display the ticks-per-time-unit fields.
Console.WriteLine(numberFmt, "Ticks per day", TimeSpan.TicksPerDay);
Console.WriteLine(numberFmt, "Ticks per hour", TimeSpan.TicksPerHour);
Console.WriteLine(numberFmt, "Ticks per minute", TimeSpan.TicksPerMinute);
Console.WriteLine(numberFmt, "Ticks per second", TimeSpan.TicksPerSecond);
Console.WriteLine(numberFmt, "Ticks per millisecond", TimeSpan.TicksPerMillisecond);
/// <summary>
///对齐方法
/// </summary>
/// <param name="interval"></param>
/// <returns></returns>
static string Align(TimeSpan interval)
{
string intervalStr = interval.ToString();
int pointIndex = intervalStr.IndexOf(':');
pointIndex = intervalStr.IndexOf('.', pointIndex);
if (pointIndex < ) intervalStr += " ";
return intervalStr;
}
未完待续。。。。
TimeSpan时间间隔的更多相关文章
- TimeSpan时间间隔详解
1 public string GetShiXian(string fadanshijian) 2 { 3 string result,chulishijian; 4 5 DateTime fdTim ...
- C#基础:命令解析
1.普通格式命令的解析 例如: RENA<SP>E:\\A.txt<SP>C:\\B.txt<CRLF> (SP -> 空格,CRLF -> 回车加换行 ...
- JAVA 文本 TXT 操作工具类
import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; imp ...
- JAVA Date超强工具类,可直接取代util.Date使用
package net.maxt.util; import java.text.DateFormat; import java.text.ParseException; import java.tex ...
- Unity3D实现DoubleClick的一种方法
代码简单粗暴如下: void OnMouseDown() { ) { t2 = DateTime.Now; , , , , )) //时间间隔小于500ms,认为是双击 { // 双击后的操作 } t ...
- Wpf自动滚动效果
一.思路 1.使用ScrollView的Scroll.ScrollToVerticalOffset(offset)方法进行滚动 2.ScrollView中放置2个ListView,第一个滚动出边界后, ...
- 使用DateAdd方法向指定日期添加一段时间间隔,使用TimeSpan对象获取时间间隔
一:使用DateAdd方法向指定日期添加一段时间间隔,截图 二:代码 using System; using System.Collections.Generic; using System.Comp ...
- [转载]C# TimeSpan 计算时间差(时间间隔)
TimeSpan 结构 表示一个时间间隔. 命名空间:System 程序集:mscorlib(在 mscorlib.dll 中) 说明: 1.DateTime值类型代表了一个从公元0001年1月1日 ...
- 使用TimeSpan对象获取时间间隔
实现效果: 关键知识: TimeSpan对象表是时间间隔或持续时间,两个DateTime对象相减,则会得到一个TimeSpan对象 使用其days ,hours,minutes等属性 实现代码: pr ...
随机推荐
- ssh(安全协议外壳)
以下来源于百度百科 https://baike.baidu.com/item/ssh/10407?fr=aladdin SSH 为 Secure Shell 的缩写,由 IETF 的网络小组(Netw ...
- Flask deployment on gunicorn with flask script
https://stackoverflow.com/questions/34265870/flask-deployment-on-gunicorn-with-flask-script 依赖 Flask ...
- 回文串(bzoj 3676)
Description 考虑一个只包含小写拉丁字母的字符串s.我们定义s的一个子串t的“出 现值”为t在s中的出现次数乘以t的长度.请你求出s的所有回文子串中的最 大出现值. Input 输入只有一行 ...
- Named Formats!
原文发布时间为:2011-06-26 -- 来源于本人的百度文章 [由搬家工具导入] using System;using System.Text;using System.Web;using Sys ...
- 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest I. Photo Processing
题目链接 题意 将一个升序排好的数列切成若干段,要求每段的长度\(\gt k\),对每一段中最大值与最小值的差取个最大值,问这个最大值最小是多少. 思路 二分答案 怎么check呢? dp一下. d[ ...
- 汉化CodeBlock
codeblock最新版本发布了,但是对一些看不惯英文的来说,还是中文好点. 一.准备工作,先下载codeblock最新版,可以从官方下载,也可以从http://www.uzzf.com/soft/1 ...
- usb 2.0 支援的速度
from http://www.usb.org/developers/docs/usb20_docs/ high speed : 480 Mb/s full speed : 12 Mb/s low s ...
- php--获取用户ip
一般在做登录的时候有的会要求同一个帐号不能同时用不同的ip登录,这个时候我们需要获取到用户IP地址 获取ip地址的函数: function getIP() { if (getenv('HTTP_CLI ...
- 【原创】打开Excel时提示"您尝试打开的文件**.xls的格式与文件扩展名指定的格式不一致"
问题描述: 系统安装了WPS时,Analyzer导出excel时候,会提示"您尝试打开的文件**.xls的格式与文件扩展名指定的格式不一致",这是Excel的安全问题, ...
- 洛谷 P2089 烤鸡【DFS递归/10重枚举】
[链接]:https://www.luogu.org/problemnew/show/P2089 题目描述 猪猪Hanke特别喜欢吃烤鸡(本是同畜牲,相煎何太急!)Hanke吃鸡很特别,为什么特别呢? ...