日期差异编码 [英] coding of datedifference
问题描述
我正在开发图书馆管理软件
所以我需要在发行书的日期和退还书的日期之间的日期差,以便我可以很好地进行计算.
这两个日期都应直接从系统中获取,而不是从用户端获取.所以我需要一个代码.
i am working on library management software
so i need the difference of date between date on which book is issued and date on which book is returned so that i can calculate fine.
both date should be taken from system directly,not from user side.so i need a code.
推荐答案
然后您可以使用GetSystemTimeAsFileTime [
Then you can use the GetSystemTimeAsFileTime[^] function.
FILETIME is a struct, but you can use an __int64 since the memory layout matches.
__int64 currentDateAndTime;
GetSystemTimeAsFileTime((LPFILETIME)¤tDateAndTime);
SYSTEMTIME systime;
FileTimeToSystemTime((LPFILETIME)¤tDateAndTime,&systime);
在__int64上进行计算非常容易...
转换为系统时间 [
Doing the calculations on an __int64 is pretty easy ...
Convert to SYSTEMTIME[^] when you need to access the various elements of the date and time information.
Best regards
Espen Harlinn
您没有指定它是用于MFC C ++还是其他东西,因此这里是它的MFC版本...
1.获取图书发行的日期/时间:
You did not specify whether it is for MFC C++ or something else, so here''s the MFC version of it...
1. Get date/time when the book was issued:
CTime bookIssued = CTime::GetCurrentTime();
2.获取退还书籍的日期/时间:
2. Get date/time when the book was returned:
CTime bookReturned = CTime::GetCurrentTime();
3.计算天数差异:
3. Calculate the difference in days:
CTimeSpan diff = bookReturned - bookIssued;
__int64 days = diff.GetDays();
您的变量days
现在具有所需的天数.
Your variable days
now has the number of days that you need.
在 ^ ]和System.TimeSpan
[ ^ ].
[edit]
作为Espen& Vitaly指出这是一个C ++问题,所以对不起,我的回答不相关.但是,使用time()
[difftime()
[
Read up onSystem.DateTime
[^] andSystem.TimeSpan
[^].
[edit]
As Espen & Vitaly pointed out this is a C++ question so my answer is not relevant, sorry. However using thetime()
[^] anddifftime()
[^] functions of the CRT library you can achieve the same objectives.
[/edit]
这篇关于日期差异编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!