2011-05-05 5 views
4

L'exigence est d'afficher la date au format "22 janvier 2010".datepicker ne sélectionne pas le format de date personnalisé?

Je code

calanderFrom.Format = DateTimePickerFormat.Short; 
calanderFrom.CustomFormat = "dd MMM yyyy"; 

mais la date est encore à venir en format "5/5/2011". S'il vous plaît me guider comment changer de.

grâce

+0

Est-il affiché de cette façon sur le formulaire, ou est-ce qu'il retourne dans ce format à votre code? – Mikecito

+0

Vous pouvez capturer la date telle qu'elle est et la formater plus tard. C'est comme ça que je le fais. Mais je ne sais pas pourquoi cela ne fonctionne pas dans ce cas. –

Répondre

10

Remplacer

calanderFrom.Format = DateTimePickerFormat.Short; 

avec

calanderFrom.Format = DateTimePickerFormat.Custom; 
+0

+1 Vous avez raison mon pote. http://msdn.microsoft.com/fr-fr/library/system.windows.forms.datetimepicker.format%28v=VS.100%29.aspx –

3

Ne vous botter:

calanderFrom.Format = DateTimePickerFormat.Custom; 

Utilisez la valeur DateTimePickerFormat.Custom au lieu de DateTimePickerFormat.Short.

0

Vous devez définir Format pour System.Windows.Forms.DateTimePickerFormat.Custom

Changer votre code:

calanderFrom.Format = System.Windows.Forms.DateTimePickerFormat.Custom; 
calanderFrom.CustomFormat = "dd MMM yyyy"; 
1

Utilisez RFC1123 pattern. String.Format("{0:r}", dt);

Standard Date and Time Format Strings

SpecifierDateTimeFormatInfo propriétévaleur modèle (pour la culture en-US)

t ShortTimePattern h:mm tt 
d ShortDatePattern M/d/yyyy 
T LongTimePattern  h:mm:ss tt 
D LongDatePattern  dddd, MMMM dd, yyyy 
f (combination of D and t) dddd, MMMM dd, yyyy h:mm tt 
F FullDateTimePattern  dddd, MMMM dd, yyyy h:mm:ss tt 
g (combination of d and t) M/d/yyyy h:mm tt 
G (combination of d and T) M/d/yyyy h:mm:ss tt 
m, M MonthDayPattern  MMMM dd 
y, Y YearMonthPattern MMMM, yyyy 
r, R RFC1123Pattern ddd, dd MMM yyyy HH':'mm':'ss 'GMT' (*) 
s SortableDateTi­mePattern yyyy'-'MM'-'dd'T'HH':'mm':'ss (*) 
u UniversalSorta­bleDateTimePat­tern yyyy'-'MM'-'dd HH':'mm':'ss'Z' (*) 
+1

Ce n'est pas pertinent pour la question. La chaîne de format personnalisé semble être correctement configurée, le seul problème est que 'DateTimePickerFormat.Short' est utilisé à la place de la chaîne personnalisée (car elle n'est pas définie sur' DateTimePickerFormat.Custom'). – Groo

+0

Mais il pourrait le changer avec * String.Format *. RFC1123Pattern est pour ça. –

+0

* L'exigence est d'afficher la date au format "22 janvier 2010" *. – Groo

Questions connexes