当前位置:
首页 > 编程开发 > Objective-C编程 >
-
C#里操作时间的例子!
namespace Wrox.SampleCode.CSharpPreview.ChBaseClasses
{
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.WinForms;
using System.Data;
public class FormDisplayDateTimes : System.WinForms.Form
{
... as before
///
/// Summary description for FormDisplayDateTimes.
/// public FormDisplayDateTimes()
{
//
// Required for Win Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
// DateTime dtCurrTime = DateTime.Now;
AddItem("Current Time is " + dtCurrTime.ToString());
AddItem("Year is " + dtCurrTime.Year.ToString());
AddItem("Month is " + dtCurrTime.Month.ToString());
AddItem("Day of month is " + dtCurrTime.Day.ToString());
AddItem("Day of week is " + dtCurrTime.DayOfWeek.ToString());
AddItem("Hour is " + dtCurrTime.Hour.ToString());
AddItem("Minute is " + dtCurrTime.Minute.ToString());
AddItem("Second is " + dtCurrTime.Second.ToString());
AddItem("Millisecond is " + dtCurrTime.Millisecond.ToString());
AddItem("ShortDateString is " + dtCurrTime.ToShortDateString());
AddItem("LongDateString is " + dtCurrTime.ToLongDateString());
AddItem("ShortTimeString is " + dtCurrTime.ToShortTimeString());
AddItem("LongTimeString is " + dtCurrTime.ToLongTimeString());
}
public class FormTimeSpans : System.WinForms.Form
{
... as before
public FormTimeSpans()
{
//
// Required for Win Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
// constructor: TimeSpan(days, hours, minutes, seconds)
TimeSpan Span = new TimeSpan(4,2,15,0);
// initialize date to 1 Jan 2000, 12 pm
// constructor: DateTime(year,month,day,hours,minutes,seconds,
// milliseconds)
DateTime dtOld = new DateTime(2000,1,1,12,0,0,0);
DateTime dtNew = dtOld + Span;
AddItem("Original date was " + dtOld.ToLongDateString() +
" " + dtOld.ToShortTimeString());
AddItem("Adding time span of " + Span.ToString());
AddItem("Result is " + dtNew.ToLongDateString() + " " +
dtNew.ToShortTimeString());
AddItem("");
AddItem("Time span broken down is:");
AddItem("Days: " + Span.Days.ToString());
AddItem("Hours: " + Span.Hours.ToString());
AddItem("Minutes: " + Span.Minutes.ToString());
AddItem("Seconds: " + Span.Seconds.ToString());
AddItem("Milliseconds: " + Span.Milliseconds.ToString());
AddItem("Ticks: " + Span.Ticks.ToString());
AddItem("");
AddItem("TicksPerSecond: " + TimeSpan.TicksPerSecond.ToString());
AddItem("TicksPerHour: " + TimeSpan.TicksPerHour.ToString());
{
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.WinForms;
using System.Data;
public class FormDisplayDateTimes : System.WinForms.Form
{
... as before
///
/// Summary description for FormDisplayDateTimes.
///
{
//
// Required for Win Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
// DateTime dtCurrTime = DateTime.Now;
AddItem("Current Time is " + dtCurrTime.ToString());
AddItem("Year is " + dtCurrTime.Year.ToString());
AddItem("Month is " + dtCurrTime.Month.ToString());
AddItem("Day of month is " + dtCurrTime.Day.ToString());
AddItem("Day of week is " + dtCurrTime.DayOfWeek.ToString());
AddItem("Hour is " + dtCurrTime.Hour.ToString());
AddItem("Minute is " + dtCurrTime.Minute.ToString());
AddItem("Second is " + dtCurrTime.Second.ToString());
AddItem("Millisecond is " + dtCurrTime.Millisecond.ToString());
AddItem("ShortDateString is " + dtCurrTime.ToShortDateString());
AddItem("LongDateString is " + dtCurrTime.ToLongDateString());
AddItem("ShortTimeString is " + dtCurrTime.ToShortTimeString());
AddItem("LongTimeString is " + dtCurrTime.ToLongTimeString());
}
public class FormTimeSpans : System.WinForms.Form
{
... as before
public FormTimeSpans()
{
//
// Required for Win Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
// constructor: TimeSpan(days, hours, minutes, seconds)
TimeSpan Span = new TimeSpan(4,2,15,0);
// initialize date to 1 Jan 2000, 12 pm
// constructor: DateTime(year,month,day,hours,minutes,seconds,
// milliseconds)
DateTime dtOld = new DateTime(2000,1,1,12,0,0,0);
DateTime dtNew = dtOld + Span;
AddItem("Original date was " + dtOld.ToLongDateString() +
" " + dtOld.ToShortTimeString());
AddItem("Adding time span of " + Span.ToString());
AddItem("Result is " + dtNew.ToLongDateString() + " " +
dtNew.ToShortTimeString());
AddItem("");
AddItem("Time span broken down is:");
AddItem("Days: " + Span.Days.ToString());
AddItem("Hours: " + Span.Hours.ToString());
AddItem("Minutes: " + Span.Minutes.ToString());
AddItem("Seconds: " + Span.Seconds.ToString());
AddItem("Milliseconds: " + Span.Milliseconds.ToString());
AddItem("Ticks: " + Span.Ticks.ToString());
AddItem("");
AddItem("TicksPerSecond: " + TimeSpan.TicksPerSecond.ToString());
AddItem("TicksPerHour: " + TimeSpan.TicksPerHour.ToString());
最新更新
nodejs爬虫
Python正则表达式完全指南
爬取豆瓣Top250图书数据
shp 地图文件批量添加字段
爬虫小试牛刀(爬取学校通知公告)
【python基础】函数-初识函数
【python基础】函数-返回值
HTTP请求:requests模块基础使用必知必会
Python初学者友好丨详解参数传递类型
如何有效管理爬虫流量?
2个场景实例讲解GaussDB(DWS)基表统计信息估
常用的 SQL Server 关键字及其含义
动手分析SQL Server中的事务中使用的锁
openGauss内核分析:SQL by pass & 经典执行
一招教你如何高效批量导入与更新数据
天天写SQL,这些神奇的特性你知道吗?
openGauss内核分析:执行计划生成
[IM002]Navicat ODBC驱动器管理器 未发现数据
初入Sql Server 之 存储过程的简单使用
SQL Server -- 解决存储过程传入参数作为s
JavaScript判断两个数组相等的四类方法
js如何操作video标签
React实战--利用甘特图和看板,强化Paas平
【记录】正则替换的偏方
前端下载 Blob 类型整理
抽象语法树AST必知必会
关于JS定时器的整理
JS中使用Promise.all控制所有的异步请求都完
js中字符串的方法
import-local执行流程与node模块路径解析流程