DateTime数据类型的算术运算。(Arithmetic Operations on DateTime Datatype.)

   IT问题网   2021-02-18 00:00:00

问 题

嗨,



我一直试图找到一种方法对c#datetime数据类型变量进行算术运算,但我无法得到任何,

我的要求是从给定日期生成工作日索引(//星期一= 0)
vba中的
我可以直接得到这个:



  dim  weekday  as  整数 
dim newyear as 日期
newyear = dateserial( 2009 1 1
weekday = newyear mod 7




但是c#中没有提供这样的功能,可以使用other datatype变量对datetime变量进行操作。



有人有想法吗,它是用c#提供的!!?,为什么不是?



-trinadh



编辑:代码格式化。

解决方案

我建议你看看这里 [ ^ ]。这是system.datetime类的文档,其中包括操作日期的方法。

dateserial不是c#.net的一部分。原因是:



1.最初dateserial是一个vbscript函数,如下所述:

http://www.w3schools.com/vbscript/func_dateserial.asp[ ^ ]



2. 5位数的dateserial值特定于excel;我知道.net api中没有类可以提供相同的值。



尽管如此,它可以通过excel的datevalue访问来实现,通过c#使用。 net excel interop funtionality。

您是否尝试过dayofweek属性?http://msdn.microsoft.com/en-us/library/system.datetime。 dayofweek.aspx[ ^ ]



它返回枚举,可以很容易地转换为int。唯一的问题是它以sunday = 0开头,但如果你想从星期一开始,我可以减去1并用-1代替-1。

标签:数据类型算术运算



分享:

  • 微信
  • QQ好友
  • QQ空间
  • 新浪微博


热门推荐

将图像插入Word(Insert Image to Word)

problem how to compress inserted image in word using dsof ...

我如何缩进给定的XML(how can i indent a given XML)

problem is there any easiest way to indent given xml i ...

我想将Outlook消息保存到sql server db(i want to save outlook messages to sql server db)

problem hi could you please help me on saving outlook m ...

我如何在cookie中保存令牌(how I can save the token in the cookie)

problem hi, i am creating the web service au ...

C#.net中的ModalPopupExtender(ModalPopupExtender in C#.net)

problem while i am clicking the modal popup extender wind ...

需要帮助来更改密码表格(need help to change password form)

problem hi everyone, i am still newbie in vb. ...

CMap或CMapPtrToPtr(CMap or CMapPtrToPtr)

problem hi, i want store the objects in cmap ...

如何创建新的任务栏(how to create new task bar)

problem hi, i want to create new taskbar,can any one hel ...

在C#.net中旋转PDF文件(Rotate PDF File in C#.net)

problem hi , how to rotate pdf file in c#.net ...

在C#.Net中旋转图像文件(Rotate Image Files in C#.Net)

problem hi, how to rotate image files(jpeg,ti ...

如何交换字符串中的字符(how to swap characters in a string)

problem hi all. i''m new in .net and i want t ...

如何在SHAREPOINT 2010中集成twitter(How to integrate twitter in SHAREPOINT 2010)

problem hi to all, this is siddiqali working ...

检查应用程序是否正在运行(Check If Application Is Running)

problem is there a way to run a loop that wou ...

如何使用radiobuttonlist?(how to use radiobuttonlist)

problem i want to write select query for selectedindexcha ...

如何计算日期差异和数字差异(How to Calculate Date Diff And Num Diff)

problem glnotranscationdate deposit withdraw transid loan ...

ie6浏览器问题在我的网页上(ie6 browser issue in my web page)

problem my webpage displaying 1 inleft bottom corner only ...

无法在表单上使用控件。(Unable to use controls on the form.)

problem hi, i have created some static insta ...

如何在Javascript中使用正则表达式匹配定义的模式(How to match defined pattern using regular expression in Javascript)

problem hi, first, there is a string called: var bookpat ...

我想打印收据,但我遇到了问题(I want to print a reciept but i face a problem)

problem in this project i am using datareport ...

Visual Studio 2010 + Windows 7 + 64位计算机+ C ++ + 32位DLLS = 3个问题(Visual Studio 2010 + Windows 7 + 64-bit computer + C++ + 32 bit DLLS = 3 problems)

problem i''ve been using visual studio 2005 for many year ...