Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 648
  • Last Modified:

time_t to Unicode string

Hello,

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

Ingo
0
Ocrana
Asked:
Ocrana
  • 6
  • 3
1 Solution
 
evilrixSenior Software Engineer (Avast)Commented:
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
 
OcranaAuthor Commented:
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
 
evilrixSenior Software Engineer (Avast)Commented:
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
evilrixSenior Software Engineer (Avast)Commented:
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
 
OcranaAuthor Commented:
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
 
evilrixSenior Software Engineer (Avast)Commented:
>> 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
 
evilrixSenior Software Engineer (Avast)Commented:
>> 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
 
OcranaAuthor Commented:
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
 
evilrixSenior Software Engineer (Avast)Commented:
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now