-
January 22nd, 2007, 05:36 AM
#1
convert time_t to CString
Hi,
how can I convert time_t to CString? (I need the seconds since midnight 01.01.1970 as a CString.
Thanks in advance!
radu
Please rate if it helps!
* The second mouse gets the cheese.
* Birthdays are good for you. The more you have, the longer you live.
* Always keep your words soft and sweet, just in case you have to eat them.
* Always read stuff that will make you look good if you die in the middle of it.
-
January 22nd, 2007, 05:45 AM
#2
Re: convert time_t to CString
Do you mean Something Like this.
Code:
time_t aclock;
struct tm *newtime;
time( &aclock ); // Get time in seconds
newtime = localtime( &aclock ); // Convert time to struct tm form
CString str = asctime(newtime);
Thanx
-
January 22nd, 2007, 06:06 AM
#3
Re: convert time_t to CString
Since time_t is an unsigned int you can use CString member function Format for converting it.
For eg:
CString csTimeConv;
csTimeConv.Format( _T( "%u", tYour_time_t );
-
January 22nd, 2007, 06:57 AM
#4
Re: convert time_t to CString
Originally Posted by thomas_nibu
Since time_t is an unsigned int you can use CString member function Format for converting it.
For eg:
CString csTimeConv;
csTimeConv.Format( _T( "%u", tYour_time_t );
yeah . .but that gives you a number. . in fact. . it 's the secondcount from '1970 jan 1'
so .. in your case it would be 'the current time is 16899024' or something like that.. . It think the TS wants a displayable time.
-
January 22nd, 2007, 07:10 AM
#5
Re: convert time_t to CString
Thanks guys!
I was looking for the solution given by thomas_nibu. Just wanted to have the number as CString.
Have a nice day!
radu
Please rate if it helps!
* The second mouse gets the cheese.
* Birthdays are good for you. The more you have, the longer you live.
* Always keep your words soft and sweet, just in case you have to eat them.
* Always read stuff that will make you look good if you die in the middle of it.
-
January 22nd, 2007, 07:13 AM
#6
Re: convert time_t to CString
Skizmo,
He said that he want's the number. Not a formatted one.
-
January 22nd, 2007, 07:14 AM
#7
Re: convert time_t to CString
Originally Posted by thomas_nibu
Skizmo,
He said that he want's the number. Not a formatted one.
yeah . .My mistake. .. I noticed after posting
-
January 22nd, 2007, 07:17 AM
#8
Re: convert time_t to CString
one more question:
I am getting 5 bytes data. Isn't it supposed to be 4 bytes? i.e. now I was getting 1169467720
Please rate if it helps!
* The second mouse gets the cheese.
* Birthdays are good for you. The more you have, the longer you live.
* Always keep your words soft and sweet, just in case you have to eat them.
* Always read stuff that will make you look good if you die in the middle of it.
-
January 22nd, 2007, 07:40 AM
#9
Re: convert time_t to CString
First thing OP Doesn't Mention in His First Post What is his Actual Requirement.He Simply asked how to convert time_t to CString. So Anyone will think that might be he want some formatted text so he can use somewhere or he want to print it in some control etc etc.So it's always good if you Specify your question in a efficient manner so you can get a proper answer of your question.
Thanx
-
January 22nd, 2007, 07:45 AM
#10
Re: convert time_t to CString
Originally Posted by humptydumpty
First thing OP Doesn't Mention in His First Post What is his Actual Requirement.He Simply asked how to convert time_t to CString. So Anyone will think that might be he want some formatted text so he can use somewhere or he want to print it in some control etc etc.So it's always good if you Specify your question in a efficient manner so you can get a proper answer of your question.
Thanx
well, I think "I need the seconds since midnight 01.01.1970 as a CString" should be clear enough. There is nothing mentioned about "formatted" in my post.
Please rate if it helps!
* The second mouse gets the cheese.
* Birthdays are good for you. The more you have, the longer you live.
* Always keep your words soft and sweet, just in case you have to eat them.
* Always read stuff that will make you look good if you die in the middle of it.
-
January 22nd, 2007, 08:04 AM
#11
Re: convert time_t to CString
Originally Posted by Radu
one more question:
I am getting 5 bytes data. Isn't it supposed to be 4 bytes? i.e. now I was getting 1169467720
Format it as hex value (Format( _T( "%x", tYour_time_t )) and you'll get 4 bytes.
-
January 22nd, 2007, 08:06 AM
#12
Re: convert time_t to CString
oh man, ..
sure!
Please rate if it helps!
* The second mouse gets the cheese.
* Birthdays are good for you. The more you have, the longer you live.
* Always keep your words soft and sweet, just in case you have to eat them.
* Always read stuff that will make you look good if you die in the middle of it.
-
January 23rd, 2007, 10:42 PM
#13
Re: convert time_t to CString
Originally Posted by VictorN
Format it as hex value (Format( _T( "% x", tYour_time_t )) and you'll get 4 bytes.
-
January 24th, 2007, 03:34 AM
#14
Re: convert time_t to CString
Originally Posted by VictorN
Format it as hex value (Format( _T( "% x", tYour_time_t )) and you'll get 4 bytes.
Correction: in order to always get four bytex for int/long value the format specification must be a little changed:
Code:
CString csTimeConv;
csTimeConv.Format( _T( "%08x", tYour_time_t );
// or
csTimeConv.Format( _T( "% 8x", tYour_time_t );
Last edited by VictorN; January 24th, 2007 at 04:39 AM.
-
January 24th, 2007, 04:36 AM
#15
Re: convert time_t to CString
Thanks Victor!
Please rate if it helps!
* The second mouse gets the cheese.
* Birthdays are good for you. The more you have, the longer you live.
* Always keep your words soft and sweet, just in case you have to eat them.
* Always read stuff that will make you look good if you die in the middle of it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|