Click here to Skip to main content
15,917,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've been searching for codes that could output like "1st of February 2016" based on the datetimepicker date i chose.

Is there a custom format for that? Thanks in advance!

What I have tried:

For the meantime, I rely on the datetime.now.toString("MMMM dd,yyyy").
Posted

1 solution

Hi!

The best way is to make a own function that retrieves the desired format that you want.

But according to this:
M       One-digit month number.
d       One-digit day of the month.
HH      Two-digit hours on 24-hour scale.
mm      Two-digit minutes.
yy      Two-digit year.


You also can try this options:
VB.NET
Sub Main()
    Dim Rightnow As DateTime = DateTime.Now
    MessageBox.Show(Rightnow.ToString("d"))
    MessageBox.Show(Rightnow.ToString("D"))
    MessageBox.Show(Rightnow.ToString("f"))
    MessageBox.Show(Rightnow.ToString("F"))
    MessageBox.Show(Rightnow.ToString("g"))
    MessageBox.Show(Rightnow.ToString("G"))
    MessageBox.Show(Rightnow.ToString("m"))
    MessageBox.Show(Rightnow.ToString("M"))
    MessageBox.Show(Rightnow.ToString("o"))
    MessageBox.Show(Rightnow.ToString("O"))
    MessageBox.Show(Rightnow.ToString("s"))
    MessageBox.Show(Rightnow.ToString("t"))
    MessageBox.Show(Rightnow.ToString("T"))
    MessageBox.Show(Rightnow.ToString("u"))
    MessageBox.Show(Rightnow.ToString("U"))
    MessageBox.Show(Rightnow.ToString("y"))
    MessageBox.Show(Rightnow.ToString("Y"))
End Sub


And that will show something like:
"13/02/2016"
"dissabte, 13 de febrer de 2016"
"dissabte, 13 de febrer de 2016 12:23"
"dissabte, 13 de febrer de 2016 12:23:56"
"13/02/2016 12:23"
"13/02/2016 12:23:56"
"13 de febrer"
"13 de febrer"
"2016-02-13T12:23:56.9722631+01:00"
"2016-02-13T12:23:56.9722631+01:00"
"2016-02-13T12:23:56"
"12:23"
"12:23:56"
"2016-02-13 12:23:56Z" &
"dissabte, 13 de febrer de 2016 11:23:56" &
"de febrer de 2016"
"de febrer de 2016"

My results appears in Catalan because of the regional config :P

Hope this helps you! ;)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900