Solved

time_t to Unicode string

Posted on 2012-04-13
9
625 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 500 total points
ID: 37841994
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

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.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

710 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