System Date & Time

Posted on 1999-08-18
Medium Priority
Last Modified: 2010-04-15
How do I obtain the system date n time?  Every pc's system date n time is set to a different format, for example...
1999-05-06 or 06-05-1999 or 06/05/1999.  What's the command to use to get the format of the system date so that I can let the user know what type of date format should be entered .  Thanks.
Question by:pearl1

Expert Comment

ID: 1264579
You don't really need to :)
There are system calls (time()  in C?) that give you a number independent of format (I think it was number of seconds since 1980 in a PC); and then you can transform it to whatever format you want it (I'm sure they are functions for this in C too, just can't remember their names, check documentation for time.h or sys/time.h).

If you really want the format the system is using, you may also try asking in a OS specific forum (I assume you are using some version of Windows, since you talk about a PC as it that's enhough info ... :)

LVL 11

Accepted Solution

alexo earned 80 total points
ID: 1264580
For a Win32 platform use GetSystemTime() or GetLocalTime().  You can retrieve strings for any given time or date in a format that is appropriate for the current locale by using the GetTimeFormat() and GetDateFormat() functions.  Also see EnumDateFormats() and EnumTimeFormats().

In plain C gives you use gmtime() or localtime() to query the time, asctime() to convert it to a (system defined) string or strftime() which lets you control the format.

Please ask Windows-specific questions in the Windows programming area.
Please ask MFC-specific questions in the MFC area.

Expert Comment

ID: 6820353
This question was awarded, but never cleared due to the JSP-500 errors of that time.  It was "stuck" against userID -1 versus the intended expert whom you awarded.  This corrects that and the expert will now receive these points, all verified.
Moderator @ Experts Exchange

Featured Post

A proven path to a career in data science

At Springboard, we know how to get you a job in data science. With Springboard’s Data Science Career Track, you’ll master data science  with a curriculum built by industry experts. You’ll work on real projects, and get 1-on-1 mentorship from a data scientist.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

587 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