Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

time_t to Unicode string

Posted on 2012-04-13
9
Medium Priority
?
639 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
[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
  • 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 2000 total points
ID: 37841994
0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
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

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Six Sigma Control Plans

730 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