Solved

time_t to Unicode string

Posted on 2012-04-13
9
618 Views
Last Modified: 2012-04-13
Hello,

how can I format/convert a time_t info into a unicode CString?

Ingo
0
Comment
Question by:Ocrana
  • 6
  • 3
9 Comments
 
LVL 40

Expert Comment

by:evilrix
ID: 37841958
Depends. What conversion format to you want to use for the time_t value or do you mean store the literal value of the time_t object?
0
 

Author Comment

by:Ocrana
ID: 37841984
Hi,

I want to print this information on screen. Maybe with "YYYY-MM-DD HH:MM:SS" or just "YYYY-MM-DD". I tried it some ways but I just get cryptical text in my final CString, so the conversion method maybe wrong. Not, I use Unicode.

Ingo
0
 
LVL 40

Accepted Solution

by:
evilrix earned 500 total points
ID: 37841994
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 40

Expert Comment

by:evilrix
ID: 37842007
BTW: You need to understand that there is a big difference between using a "wide" data type and "Unicode" Just because something is in a wide format does not mean it is a Unicode character nor encoded using one of the Unicode transformation formats. In other words, using a wide type doesn't magically make your string Unicode encoded... the encoding still needs to be handled by you using one of the many Unicode encoding/decoding libraries (either those included with your OS or something like ICU, which is pretty much the defacto standard).
0
 

Author Comment

by:Ocrana
ID: 37842070
I really do not understand why I need to decode/encode something in my software that use unicode strings.  Also I do not see any sense of a additional library. Iam looking for a easy solution. One I found now is: CTime(deviceInformationEx.FirmwareCreationDate).Format(_T("%c"))

But thanks for the messages.

Ingo
0
 
LVL 40

Expert Comment

by:evilrix
ID: 37842088
>> I really do not understand why I need to decode/encode something in my software that use unicode strings
I'm just pointing out that storing something in wide format doesn't necessarily mean it's Unicode. Unicode is a character-set and that is normally represented using one of the encoding formats (eg. UTF8, 16 or 32). You can, for example, represent Unicode quite easily using char rather than wchar_t (narrow vs. wide). Likewise, I can store characters sets other than Unicode in wide format.

What I'm trying to say is don't confuse using a wide data type with the character-set/encoding format; they are not the same thing. Let me put it another way, I'm from the UK and if I visit France that doesn't automatically mean I am speaking in French :)
0
 
LVL 40

Expert Comment

by:evilrix
ID: 37842106
>> One I found now is: CTime(deviceInformationEx.FirmwareCreationDate).Format(_T("%c"))
Again, that may very well return values in a wide format but that doesn't mean they are in Unicode. They could be in UTF16 format (an encoding format used to represent Unicode using 2 bytes) but that could also be a character set that is not Unicode. Unfortunately, the documentation isn't clear on what format is returned. Given that you're using Visual Studio you should find that the default encoding format is, indeed, UTF16. I'm just trying to ensure you understand that this is an arbitrary decision by Microsoft and on other platforms you may find that a different encoding format is used (for example, on Linux you'll generally find UTF32 is the preferred encoding format).

Anyway, if you don't care about that and you're always coding on Microsoft you can probably just assume all wide strings will be UTF16 encoded Unicode :)
0
 

Author Comment

by:Ocrana
ID: 37842152
I know that every system has different formats.
But please understand, I use Categories "C++TopicsC++ Programming Language ,Miscellaneous Programming ,Microsoft Developmen" and TAgs "MFC, C++" for this question. So I think it is clear that my concern is not Linux and MAC or whatever.
However, I respect you answers and again many thanks for your help, because your answer brings me in google to the solution.  ;)

Ingo
0
 
LVL 40

Expert Comment

by:evilrix
ID: 37842162
No problem. Sorry, I wasn't trying to confuse you I just wanted to be sure that you understood that just because you have a result in a data type that is wide doesn't mean you have a result in a Unicode format. As you as (a) you understand that and (b) you know your system will give you a result in that format then I'd say you probably now know as much as I do :)

Best of luck.
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

A short article about a problem I had getting the GPS LocationListener working.
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

820 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