How to Calculate difference between two dates in C# z
Do you need to find the difference in number of days, hours or even minute between the two date range?
Here's how:
Assuming the a and b variable is of type DateTime object.
DateTime a = DateTime.Now;
DateTime b = DateTime.Now
(b - a).TotalDays

Example:
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.dateTimePicker1.CustomFormat = "MM/dd/yyyy HH:mm";
this.dateTimePicker1.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
}
private void button1_Click(object sender, EventArgs e)
{
//Calculate the total number of days
textBox1.Text = (dateTimePicker2.Value - dateTimePicker1.Value).TotalDays.ToString("#");
//Calculate the total number of hours
textBox2.Text = (dateTimePicker2.Value - dateTimePicker1.Value).TotalHours.ToString("#");
//Other options are total of minutes, seconds and milliseconds.
}
}
}
How to Calculate difference between two dates in C# z的更多相关文章
- Calculate difference between consecutive data points in a column from a file
cat > temp0015101269125 awk 'p{print $0-p}{p=$0}' temp00152-633-7 REF: https://www.unix.com/shel ...
- Java 两个日期间的天数计算
在Java中计算两个日期间的天数,大致有2种方法:一是使用原生JDK进行计算,在JDK8中提供了更为直接和完善的方法:二是使用第三方库. 1.使用原生的JDK private static long ...
- 46 个非常有用的 PHP 代码片段
在编写代码的时候有个神奇的工具总是好的!下面这里收集了 40+ PHP 代码片段,可以帮助你开发 PHP 项目. 这些 PHP 片段对于 PHP 初学者也非常有帮助,非常容易学习,让我们开始学习吧- ...
- 56个PHP开发常用代码
2016/02/14 6203 4 在编写代码的时候有个神奇的工具总是好的!下面这里收集了 50+ PHP 代码片段,可以帮助你开发 PHP 项目. 这些 PHP 片段对于 PHP 初学者也非常 ...
- [转]Date and String Function in BluePrism
本文转自:https://www.codeproject.com/Articles/1247389/Date-and-String-Function-in-BluePrism This article ...
- php 常用的自定义函数
1. 发送 SMS 在开发 Web 或者移动应用的时候,经常会遇到需要发送 SMS 给用户,或者因为登录原因,或者是为了发送信息.下面的 PHP 代码就实现了发送 SMS 的功能. 为了使用任何的语言 ...
- PHP实用代码片段(三)
1. 目录清单 使用下面的 PHP 代码片段可以在一个目录中列出所有文件和文件夹. function list_files($dir) { if(is_dir($dir)) { if($handle ...
- 45 Useful Oracle Queries--ref
http://viralpatel.net/blogs/useful-oracle-queries/ Here’s a list of 40+ Useful Oracle queries that e ...
- 【转】46 个非常有用的 PHP 代码片段
1. 发送 SMS 在开发 Web 或者移动应用的时候,经常会遇到需要发送 SMS 给用户,或者因为登录原因,或者是为了发送信息.下面的 PHP 代码就实现了发送 SMS 的功能. 为了使用任何的语言 ...
随机推荐
- qsort()与besearch()
功 能: 使用快速排序例程进行排序 头文件:stdlib.h 用 法: void qsort(void *base,int nelem,int width,int (*fcmp)(const void ...
- android Notification定义与应用
首先要明白一个概念: Intent 与 PendingIntent 的区别: Intent:是意图,即告诉系统我要干什么,然后做Intent应该做的事,而intent是消息的内容 PendingInt ...
- IOS NSPredicate 查询、搜索
简述:Cocoa框架中的NSPredicate用于查询,原理和用法都类似于SQL中的where,作用相当于数据库的过滤取. 最常用到的函数 + (NSPredicate *)predicateWith ...
- Android ActionBar下拉选项
package com.example.actionBarTest.actionBarList; import android.app.ActionBar; import android.app.Ac ...
- Web中的监听器【Listener】与过滤器【Filter】 实例
监听器实例: package com.gwssi.listener; import javax.servlet.http.HttpSession; import javax.servlet.http. ...
- 【Linux高频命令专题(21)】df
概述 linux中df命令的功能是用来检查linux服务器的文件系统的磁盘空间占用情况.可以利用该命令来获取硬盘被占用了多少空间,目前还剩下多少空间等信息. 显示指定磁盘文件的可用空间.如果没有文件名 ...
- SpringMVC学习总结(三)——Controller接口详解(1)
4.12.ParameterizableViewController 参数化视图控制器,不进行功能处理(即静态视图),根据参数的逻辑视图名直接选择需要展示的视图. <bean name=&quo ...
- mysql外键详解
1.1.MySQL中“键”和“索引”的定义相同,所以外键和主键一样也是索引的一种.不同的是MySQL会自动为所有表的主键进行索引,但是外键字段必须由用户进行明确的索引.用于外键关系的字段必须在所有的参 ...
- CreateTwoArray
public class CreateTwoArray{ public static void main(String []args){ int[][]arr=new int [2][3]; Syst ...
- Intellij idea使用postgresql 反向生成实例, 'Basic' attribute type should not be 'Object'
mapped type不能Object? 本人使用 intellij idea 15 , postgresql 9.4,在开发java ee . 在用 Hibernate时, 需要用数据库表反向生成实 ...