当前位置: 首页 > news >正文

十堰优化网站公司重庆社区官网

十堰优化网站公司,重庆社区官网,wordpress custom post type,已备案域名购买网址低价目录 一、基本方法 1.用 DateAndTime.DateAdd方法添加一段时间间隔 2.用DateTime.Add方法添加一段时间间隔 二、实例 1.实例1:用 DateAndTime.DateAdd方法 2.实例2:用DateTime.Add方法 一、基本方法 1.用 DateAndTime.DateAdd方法添加一段时间间隔…

目录

一、基本方法

1.用 DateAndTime.DateAdd方法添加一段时间间隔

2.用DateTime.Add方法添加一段时间间隔

二、实例

1.实例1:用 DateAndTime.DateAdd方法

2.实例2:用DateTime.Add方法


一、基本方法

1.用 DateAndTime.DateAdd方法添加一段时间间隔

        用了DateAndTime类的DateAdd静态方法。

        返回一个 Date 值,其中包含已添加指定时间间隔的日期和时间值。

        使用DateAndTime类的DateAdd静态方法可以方便地向指定日期添加一段时间间隔。语法格式如下:

DateAndTime.DateAdd(Datelnterval interval,double Number,DateTime DateValue);参数说明
interval:表示添加时间间隔的枚举值。
Number:表示要添加的时间间隔数,如果interval的枚举值为day,Number值为1,则向当前时间对象添加1天。
DateValue:表示当前操作的时间对象。

2.用DateTime.Add方法添加一段时间间隔

        使用DateTime的Add方法也可以向指定日期添加一段时间间隔。

        DateTime.Add方法接收一个TimeSpan对象作为参数,用于向当前DateTime中添加一段时间间隔。所以也可以使用DateTime的Add方法代替DateAdd方法实现相同的添加时间间隔的效果。

        返回一个新的 DateTime,它将指定 TimeSpan 的值添加到此实例的值上。

public DateTime Add (TimeSpan value);参数
value    TimeSpan
正或负时间间隔。返回
DateTime
一个对象,其值是此实例所表示的日期和时间与 value 所表示的时间间隔之和。例外
ArgumentOutOfRangeException
生成的 DateTime 小于 DateTime.MinValue 或大于 DateTime.MaxValue。注解
可以使用 Add 方法在单个操作中添加多种类型的时间间隔, (天、小时、分钟、秒或毫秒) 。 此方法的行为与加法运算符的行为相同。 结构 DateTime 还支持每个时间间隔的专用加法 (如 AddDays、 AddHours和 AddMinutes) 。执行日期算术时, Add 方法会考虑闰年和一个月中的天数。此方法不会更改此 DateTime的值。 相反,它返回一个新的 DateTime ,其值是此操作的结果。 新DateTime实例的 属性与当前实例的 属性相同。

二、实例

1.实例1:用 DateAndTime.DateAdd方法

// 用 DateAndTime.DateAdd方法添加一段时间间隔
using Microsoft.VisualBasic;namespace _063
{public partial class Form1 : Form{private GroupBox? groupBox1;private Button? button3;private Button? button2;private Button? button1;private Label? label1;private Button? button4;public DateTime datetime;//定义时间字段public Form1(){InitializeComponent();Load += Form1_Load;}private void Form1_Load(object? sender, EventArgs e){// // label1// label1 = new Label{AutoSize = true,Location = new Point(6, 28),Name = "label1",Size = new Size(44, 17),TabIndex = 0,Text = "时间:"};// // button1// button1 = new Button{Location = new Point(6, 133),Name = "button1",Size = new Size(75, 23),TabIndex = 1,Text = "加1分钟",UseVisualStyleBackColor = true};button1.Click += Button1_Click;// // button2// button2 = new Button{Location = new Point(98, 133),Name = "button2",Size = new Size(75, 23),TabIndex = 2,Text = "加1小时",UseVisualStyleBackColor = true};button2.Click += Button2_Click;// // button3// button3 = new Button{Location = new Point(190, 133),Name = "button3",Size = new Size(75, 23),TabIndex = 3,Text = "加1天",UseVisualStyleBackColor = true};button3.Click += Button3_Click;// // button4// button4 = new Button{Location = new Point(282, 133),Name = "button4",Size = new Size(75, 23),TabIndex = 4,Text = "减1天",UseVisualStyleBackColor = true};button4.Click += Button4_Click;// // groupBox1// groupBox1 = new GroupBox{Location = new Point(12, 12),Name = "groupBox1",Size = new Size(365, 162),TabIndex = 0,TabStop = false,Text = "添加时间间隔"};groupBox1.Controls.Add(button4);groupBox1.Controls.Add(button3);groupBox1.Controls.Add(button2);groupBox1.Controls.Add(button1);groupBox1.Controls.Add(label1);groupBox1.SuspendLayout();// // Form1// AutoScaleDimensions = new SizeF(7F, 17F);AutoScaleMode = AutoScaleMode.Font;ClientSize = new Size(389, 186);Controls.Add(groupBox1);Name = "Form1";StartPosition = FormStartPosition.CenterScreen;Text = "向指定日期添加一段时间间隔";groupBox1.ResumeLayout(false);groupBox1.PerformLayout();datetime = DateTime.Now;//得到系统当前时间label1!.Text += Environment.NewLine + datetime.ToString("  yyyy年M月d日 H时m分s秒");//显示时间信息}/// <summary>/// 加1分钟/// </summary>private void Button1_Click(object? sender, EventArgs e){datetime = DateAndTime.DateAdd(DateInterval.Minute, 1, datetime);label1!.Text += Environment.NewLine + datetime.ToString("  yyyy年M月d日 H时m分s秒");}/// <summary>/// 加1小时/// </summary>private void Button2_Click(object? sender, EventArgs e){datetime = DateAndTime.DateAdd(DateInterval.Hour, 1, datetime);label1!.Text += Environment.NewLine + datetime.ToString("  yyyy年M月d日 H时m分s秒");}/// <summary>/// 加1天/// </summary>private void Button3_Click(object? sender, EventArgs e){datetime = DateAndTime.DateAdd(DateInterval.Day, 1, datetime);label1!.Text += Environment.NewLine + datetime.ToString("  yyyy年M月d日 H时m分s秒");}/// <summary>/// 减1天/// </summary>private void Button4_Click(object? sender, EventArgs e){datetime = DateAndTime.DateAdd(DateInterval.Day, -1, datetime);label1!.Text += Environment.NewLine + datetime.ToString("  yyyy年M月d日 H时m分s秒");}}
}

 

2.实例2:用DateTime.Add方法

// Add 方法计算从此刻起 1天 (864 小时) 后是星期几
namespace _063_1
{internal class Program{private static void Main(string[] args){ArgumentNullException.ThrowIfNull(args);DateTime today = DateTime.Now;TimeSpan duration = new(1, 0, 0, 0);DateTime answer = today.Add(duration);Console.WriteLine("{0:dd}", answer);      // DayConsole.WriteLine("{0:ddd}", answer);    // Day nameConsole.WriteLine("{0:dddd}", answer);  // Full day name}}
}
//运行结果:
/*
27
周六
星期六*/

http://www.yayakq.cn/news/127608/

相关文章:

  • 外贸在什么网站做网页素材网站有哪些
  • 网站建设 业务培训wordpress恢复主题
  • 免费个人logo设计网站公司网站怎么申请怎么注册
  • 网站产品页如何做优化网站开发技术与应用课程设计
  • 影楼模板网站如何做好电子商务网站开发
  • 网站建设等级定级什么网站可以做宣传
  • 深圳网站建设 site江苏城市建设档案馆网站
  • 企业网站管理系统的运维服务新冠北京最新消息
  • 内蒙古住房与城乡建设厅网站网址早期网站开发用的技术
  • 简单的网站建设公司的模板下载WordPress登录不进
  • 同一个域名两个网站界面设计论文
  • 建设学院网站的意义网站建设哪家性价比高
  • 沈阳网站建设德泰诺建设银行海外分行招聘网站
  • 上海营销网站建设公司企业网站网页
  • 1688网站可以做全屏吗小游戏网站代码
  • 制作网站页面怎么做新校区建设专题网站
  • 社交网站页面设计开发wordpress插件如何防破解
  • 邵阳住建部网站中国乌镇互联网国际峰会
  • 网站建设邮箱免费自助建站网站建设中iis
  • 高邑做网站为什么网站不见了
  • 做植物提取物的专业网站创新型的赣州网站建设
  • 深圳优秀网站建设定制好用吗
  • 糗事百科网站模板宁波seo托管公司
  • 太原自助模板建站微小旅行社能否做网站
  • 西安网站开发工程师网页设计流程步骤
  • 创建一个网站需要做哪些工作品牌建设ppt
  • 黄岩网站建设太湖县城乡建设局网站
  • 响应式网站布局实例手机网站 跳转
  • 有模板怎么建站东平企业建站公司
  • 做网站找谁英文建站网站