WinRT : How to convert DateTime to hstring

Harshithraj1871 1,516 Reputation points
2022-11-30T07:37:14.903+00:00

Hi

I was trying to make a custom CalendarDatePicker where we can pick a date from CalendarView and also modify the date manually through the keyboard.

To achieve this, I took 2 fields, one Textbox, and one CalendarDatePicker, when we pick a date from CalendarView, I want to update the date in TextBox. That is, I want to convert the DateTime returned from CalendarDatePicker.Date Property to hstring, So that I can update the date as the string in Textbox.

I was not able to find any reference for this online. It would be of great help if you could help me with this conversion.

Thank you

Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
749 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,625 questions
{count} votes

Accepted answer
  1. Castorix31 83,096 Reputation points
    2022-11-30T10:17:02.513+00:00

    You can use DateTimeFormatter with the format you want

    For example, with a CalendarDatePicker cdp1 and a TextBox tb1 :

           DateTimeFormatter formatter(L"shortdate shorttime");  
           auto dt = formatter.Format(cdp1().Date().Value());  
           tb1().Text(dt);  
    

0 additional answers

Sort by: Most helpful