如何在vb.net中更改日期和时间值?(增加和减少) [英] how to change date and time values in vb.net?(increase & decrease)

查看:427
本文介绍了如何在vb.net中更改日期和时间值?(增加和减少)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在vb.net中如何更改日期和时间值我的意思是这样的:

例如:今天是:date1 = system.datetime.today,.....



如果x = 1那么

date1 + = 1(?这是我想知道的部分?)

date2加4小时

date3加2天12小时

date4减去1天2小时

结束如果



或者它不会像这样工作,我应该与定时器一起在指定时间内打勾?

事实上我正在使用这个与MS访问数据库的连接,我想将字段中的时间更改为特定时间。

我正在使用vb.net 2005 .net 2

in vb.net how is to change date and time values i mean like this:
for example: today is: date1 = system.datetime.today,.....

if x=1 then
date1 += 1(?this is the part i want to know?)
date2 plus 4 hours
date3 plus 2 days and 12 hours
date4 minus 1 day and 2 hours
end if

or it doesn''t work like this and i should work with timers to tick in specified time?
as a matter of fact i''m using this in a connection to MS access database, and i want to change the times in fields to a specific time.
i''m using vb.net 2005 .net 2

推荐答案

这种方式...

this way...
Dim today As System.DateTime

today = System.DateTime.Now

Dim answer1 = today.AddDays(1)  'date1 += 1
Dim answer2 = today.AddHours(4) 'date2 plus 4 hours
Dim answer3 = today.AddDays(2).AddHours(12) 'date3 plus 2 days and 12 hours
Dim answer4 = today.AddDays(-1).AddHours(-4) 'date4 minus 1 day and 2 hours



快乐编码!

:)


Happy Coding!
:)


你有什么类型的书吗?谷歌在你居住的地方工作吗?你是怎么学习VB的?你知道intellisense是什么吗?



创建一个日期时间。我们称之为约会。现在输入日期后跟一个。并且IDE将向您显示该类可用的所有方法。有一个AddDays,AddHours等。你可以给它一个负数。
Do you have any sort of books ? Does google work where you live ? How did you learn VB ? Do you know what intellisense is ?

Create a date time. Let''s call it date. Now type date followed by a . and the IDE will show you all the methods you have available for that class. There''s an AddDays, AddHours, etc. You can give it negative numbers.


这篇关于如何在vb.net中更改日期和时间值?(增加和减少)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆