Solved

time_t to Unicode string

Posted on 2012-04-13
9
608 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
 
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now