Solved

Proper date and time formate

Posted on 2002-04-16
2
329 Views
Last Modified: 2013-11-20
Hope every expert will be fine.
i want to get current date and time in the formate like this   04/15/2002 05:25:45 PM or 04/15/2002 05:25:45
tell me simple way because I am new in VC++.
waiting for Good from all experts.
Thanks
0
Comment
Question by:habibb
[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
2 Comments
 
LVL 4

Accepted Solution

by:
pagladasu earned 7 total points
ID: 6946445
CTime tNow = CTime::GetCurrentTime();
CString strNow = tNow.Format("%m/%d/%Y %H:%M %p");

strNow will contain the date and time in the desired format.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 6946947
Just a comment,

Are you sure you want it to be formatted that way?
Doesn't the user of your program expect the format to correspond with his regional settings?

If yes, then just use the most simple form of Format():

COleDateTime odt = COleDateTime::GetCurrentTime();
CString strNow = odt.Format();

Bye.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Generic progress indicator 6 119
List out all word 7 338
zeroMAx challenge 20 127
firstChar challenge 13 133
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

726 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