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 ...
随机推荐
- 个人环境搭建——搭建tomcat
搭建tomcat 和前几个软件一样,Tomcat 同样是由JAVA开发的,所以,在安装前一定要装好JDK,具体JDK搭建过程参见 个人环境搭建——搭建JDK环境 篇. 系统环境:ubuntu12. ...
- codeforces gym 100553I
codeforces gym 100553I solution 令a[i]表示位置i的船的编号 研究可以发现,应是从中间开始,往两边跳.... 于是就是一个点往两边的最长下降子序列之和减一 魔改树状数 ...
- python中文注释报错
# -*- coding: utf-8 -*-#coding=utf-8 在开头加这个
- eclspse魔板
window->prefence->搜索 template即可
- pat 甲级 1009. Product of Polynomials (25)
1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...
- Android驱动之 Linux Input子系统之TP——A/B(Slot)协议【转】
转自:http://www.thinksaas.cn/topics/0/646/646797.html 将A/B协议这部分单独拿出来说一方面是因为这部分内容是比较容易忽视的,周围大多数用到input子 ...
- shell script timer and 無限迴圈
while : do echo " infinite loop" sleep 2; done
- jenkins 管理员账号丢失
在jenkins 设置权限后,无法登录 参考: 如何修改jenkins配置权限 https://zhidao.baidu.com/question/497256501658876284.html
- 链表ADT的实现
list.h文件 /*链表的类型声明*/ typedef int ElementType; /* START: fig3_6.txt */ #ifndef _List_H #define _List_ ...
- Codeforces 899 A.Splitting in Teams
A. Splitting in Teams time limit per test 1 second memory limit per test 256 megabytes input sta ...