62,046
社区成员
发帖
与我相关
我的任务
分享
Dim time1 As DateTime
Dim time2 As DateTime
Dim res As TimeSpan
Dim a As String
time1 = "2009-12-30 15:56:39"
time2 = "2010-6-3 09:29:28"
res = time2 - time1
a = res.Hours
Dim t As Date = "2010-05-02 10:35:5"
Dim s As Integer = DateDiff(DateInterval.Second, t, Now)
Response.Write(Int(s / 3600) & "小时" & Int((s Mod 3600) / 60) & "分" & s Mod 60 & "秒")
DateTime time1 = Convert.ToDateTime("2009-12-30 15:56:39");
DateTime time2 = Convert.ToDateTime("2010-6-3 09:29:28");
TimeSpan dtTemp = time2 - time1;
Response.Write(dtTemp.Days + "天" + dtTemp.Hours + "小时" + dtTemp.Minutes + "分" + dtTemp.Seconds + "秒");
protected void Page_Load(object sender, EventArgs e)
{
DateTime time1 = Convert.ToDateTime("2009-12-30 15:56:39");
DateTime time2 = Convert.ToDateTime("2010-6-3 09:29:28");
TimeSpan dtTemp = time2 - time1;
Response.Write(dtTemp.Days + "天" + dtTemp.Hours + "小时" + dtTemp.Minutes + "分" + dtTemp.Seconds + "秒");
}
res = time2 - time1
TimeSpan res = time1 - time2;
下面是你要的结果
res.Days
res.Hours
res.Minutes
res.Seconds
Goolge一搜索 多的是!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("date1");
dt.Columns.Add("date2");
dt.Rows.Add("2009-12-30 15:56:39","2010-6-3 09:29:28");
TimeSpan dtTemp=Convert.ToDateTime(dt.Rows[0]["date2"])-Convert.ToDateTime(dt.Rows[0]["date1"]);
MessageBox.Show(dtTemp.Days + "天" + dtTemp.Hours + "小时" + dtTemp.Minutes + "分" + dtTemp.Seconds+"秒");
}
}
}
Dim t As Date = "2010-05-02 10:35:5"
Dim s As Integer = DateDiff(DateInterval.Second, t, Now)
MsgBox(Int(s / 3600) & "小时" & Int((s Mod 3600) / 60) & "分" & s Mod 60 & "秒")