Solved

C++ time functions

Posted on 2011-09-09
6
285 Views
Last Modified: 2012-06-21
I wrote a GUI application a long time ago using Borland Turbo C version 3. This ran happily on Win98SE and XP. With the jump to Windows 7, as it is a 16-bit application it will only run under XP mode (which it does).
I am now trying to bring it into the light so that it will run under w7 Ultimate (32-bit). To this end I have downloaded Microsoft Visual C++ 2010 Express. I have created a few console applications, but that isn't what I really want, so I have now converted it to a Win32 application.
The problem I now have is with the available time functions. All the functions I knew from UNIX and the Borland compiler seem to have disappeared. Some of the structures/variables still seem to be about, like time_t.
All I want to do is to be able to determine the difference in days between two dates. I have searched for this and have been reading a lot of posts in various places, but a lot still use the code that I recognise, like diffdate (or is it datediff)?. Either way I cannot access any such routine. The ctime.h header doesn't seem to exist under C++ 2010 (version 10.0).
I am finding the 'new' date routines very confusing to use, as every time I try something I get all kinds of errors about incompatible types.
Can someone point me in the right direction, preferably with example(s), so I can get on with converting the rest of the program - that needs the date difference to work?
0
Comment
Question by:norman1312
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 25

Expert Comment

by:SStory
ID: 36510295
Well, do you mean using managed code or unmanaged.
Managed in vb.net looks like this:

        Dim dt As New System.DateTime(2011, 9, 9, 8, 12, 0)
        Dim diff As System.TimeSpan = Now.Subtract(dt)

        MsgBox(diff.TotalSeconds)

This says, give me an object of DateTime, with date of Sept. 9, 2011 @ 8:12:00am.
Then it subtracts that from the current time and stores it in a TimeSpan variable.
From that you can get TotalSeconds, TotalMinutes, etc.

I C++, I'd imagine the DotNet objects are available in a similar fashion if you want to use managed code.
0
 
LVL 25

Expert Comment

by:SStory
ID: 36510307
0
 

Author Comment

by:norman1312
ID: 36510549
I'm trying to stay away from managed code if I can avoid it.
I've seen the page from the second link and had been wondering just how to use them.
Sorry to be a pain, but how does System get defined in the headers of C++?
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 25

Accepted Solution

by:
SStory earned 500 total points
ID: 36511583
This may be useful:
Part I
http://ondotnet.com/pub/a/dotnet/2003/01/13/intromcpp.html

Part II
http://ondotnet.com/pub/a/dotnet/2003/03/03/mcppp2.html

I believe it is declared as follows--from the second article

     #using <mscorlib.dll>
     using namespace System;

In vb.net you do
imports System
imports SystemData
etc.

The above is similar...just the using keyword and namespace

Be advised that writing it with managed code means the platform you write to has to have the dotnet framework installed. With Windows 7, this comes installed anyway.

If you are looking for cross platform, you'd probably not want to do managed code. So there are some things to consider.

If you want access to a huge library of objects that just work and work well, the Dotnet Framework is very powerful.
0
 

Author Closing Comment

by:norman1312
ID: 36511847
Looks like changing compilers that have developed means a LOT of reading first.
Thanks for all the help!
0
 
LVL 25

Expert Comment

by:SStory
ID: 36511969
Yes. Learning the dotnet framework can take some time. If you are only writing for Windows, then it will save you a lot of work. Of course there is Java for cross platform dev. Or unmanaged code in V C++

You are welcome.
0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question