asp.net ToString()¸ñʽ»ã×Ü
C |
»õ±Ò |
2.5.ToString("C") |
£¤2.50 |
D |
Ê®½øÖÆÊý |
25.ToString("D5") |
00025 |
E |
¿ÆѧÐÍ |
25000.ToString("E") |
2.500000E+005 |
F |
¹Ì¶¨µã |
25.ToString("F2") |
25.00 |
G |
³£¹æ |
2.5.ToString("G") |
2.5 |
N |
Êý×Ö |
2500000.ToString("N") |
2,500,000.00 |
X |
Ê®Áù½øÖÆ |
255.ToString("X") |
FF |
formatCode ÊÇ¿ÉÑ¡µÄ¸ñʽ»¯´úÂë×Ö·û´®¡££¨ÏêϸÄÚÈÝÇëËÑË÷¡°¸ñʽ»¯×Ö·û´®¡±²é¿´£©
±ØÐëÓá°{¡±ºÍ¡°}¡±½«¸ñʽÓëÆäËû×Ö·û·Ö¿ª¡£Èç¹ûÇ¡ºÃÔÚ¸ñʽÖÐҲҪʹÓôóÀ¨ºÅ£¬¿ÉÒÔÓÃÁ¬ÐøµÄÁ½¸ö´óÀ¨ºÅ±íʾһ¸ö´óÀ¨ºÅ£¬¼´£º ¡°{{¡±»òÕß¡°}}¡±¡£
³£Óøñʽ¾ÙÀý£º
£¨1£© int i=12345;
this.textBox1.Text=i.ToString();
//½á¹û 12345£¨thisÖ¸µ±Ç°¶ÔÏ󣬻ò½Ðµ±Ç°ÀàµÄʵÀý£©
this.textBox2.Text=i.ToString("d8");
//½á¹û 00012345
£¨2£© int i=123;
double j=123.45;
string s1=string.Format("the value is {0,7:d}",i);
string s2=string.Format("the value is {0,7:f3}",j);
this.textBox1.Text=s1 ;
//½á¹û the value is 123
this.textBox2.Text=s2;
//½á¹û the value is 123.450
£¨3£©double i=12345.6789;
this.textBox1.Text=i.ToString("f2"); //½á¹û 12345.68
this.textBox2.Text=i.ToString("f6");
//½á¹û 12345.678900
£¨4£©double i=12345.6789;
this.textBox1.Text=i.ToString("n"); //½á¹û 12,345.68
this.textBox2.Text=i.ToString(¡°n4¡±); //½á¹û 12,345.6789
£¨5£©double i=0.126;
string s=string.Format("the value is {0:p}",i);
this.textBox1.Text=i.ToString("p"); //½á¹û 12.6%
this.textBox2.Text=s; //½á¹û the value is 12.6%
£¨6£© DateTime dt =new DateTime(2003,5,25);
this.textBox1.Text=dt.ToString("yy.M.d");
//½á¹û 03.5.25
this.textBox2.Text=dt.ToString(¡°yyyyÄêMÔ¡±);
//½á¹û 2003Äê5ÔÂ
Convert.ToDateTime("2005/12/22 22:22:22").ToString("yyyy/MM/dd HH:mm:ss")
"2005/12/22 22:22:22"
£¨7£© int i=123;
double j=123.45;
string s=string.Format("i:{0,-7},j:{1,7}",i,j);
//-7±íʾ×ó¶ÔÆ룬ռ7λ
this.textBox1.Text=s ;
//½á¹ûi:123 ,j: 123.45
DateTime.ToString()Ó÷¨Ïê½â
ÎÒÃǾ³£»áÓöµ½¶Ôʱ¼ä½øÐÐת»»,´ïµ½²»Í¬µÄÏÔʾЧ¹û£¬Ä¬ÈϸñʽΪ:2006-6-6 14:33:34
Èç¹ûÒª»»³É³É200606,06-2006,2006-6-6»ò¸ü¶àµÄ¸ñʽ¸ÃÔõô°ìÄØ£¿
ÕâÀォҪÓõ½:DateTime.ToStringµÄ·½·¨(String, IFormatProvider)
ʾÀý£º
using System;
using System.Globalization;
String format="D";
DateTime date=DataTime.Now;
Response.Write(date.ToString(format, DateTimeFormatInfo.InvariantInfo));
½á¹ûÊä³ö
Thursday, June 16, 2006
ÔÚÕâÀïÁгöÁ˲ÎÊýformat¸ñʽÏêϸÓ÷¨
=======================
¸ñʽ×Ö·û ¹ØÁªÊôÐÔ/˵Ã÷
d ShortDatePattern
D LongDatePattern
f ÍêÕûÈÕÆÚºÍʱ¼ä£¨³¤ÈÕÆںͶÌʱ¼ä£©
F FullDateTimePattern£¨³¤ÈÕÆںͳ¤Ê±¼ä£©
g ³£¹æ£¨¶ÌÈÕÆںͶÌʱ¼ä£©
G ³£¹æ£¨¶ÌÈÕÆںͳ¤Ê±¼ä£©
m¡¢M MonthDayPattern
r¡¢R RFC1123Pattern
s ʹÓõ±µØʱ¼äµÄ SortableDateTimePattern£¨»ùÓÚ ISO 8601£©
t ShortTimePattern
T LongTimePattern
u UniversalSortableDateTimePattern ÓÃÓÚÏÔʾͨÓÃʱ¼äµÄ¸ñʽ
U ʹÓÃͨÓÃʱ¼äµÄÍêÕûÈÕÆÚºÍʱ¼ä£¨³¤ÈÕÆںͳ¤Ê±¼ä£©
y¡¢Y YearMonthPattern
ϱíÁгöÁ˿ɱ»ºÏ²¢ÒÔ¹¹Ôì×Ô¶¨ÒåģʽµÄģʽ
========================================
ÕâЩģʽÊÇÇø·Ö´óСдµÄ£»ÀýÈ磬ʶ±ð¡°MM¡±£¬µ«²»Ê¶±ð¡°mm¡±¡£Èç¹û×Ô¶¨Òåģʽ°üº¬¿Õ°××Ö·û»òÓõ¥ÒýºÅÀ¨ÆðÀ´µÄ×Ö·û£¬ÔòÊä³ö×Ö·û´®Ò³Ò²½«°üº¬ÕâЩ×Ö·û¡£Î´¶¨ÒåΪ¸ñʽģʽµÄÒ»²¿·Ö»ò䶨ÒåΪ¸ñʽ×Ö·ûµÄ×Ö·û°´ÆäÔÒ帴ÖÆ¡£
¸ñʽģʽ ˵Ã÷ £º
d ÔÂÖеÄijһÌ졣һλÊýµÄÈÕÆÚûÓÐÇ°µ¼Áã¡£
dd ÔÂÖеÄijһÌ졣һλÊýµÄÈÕÆÚÓÐÒ»¸öÇ°µ¼Áã¡£
ddd ÖÜÖÐijÌìµÄËõдÃû³Æ£¬ÔÚ AbbreviatedDayNames Öж¨Òå¡£
dddd ÖÜÖÐijÌìµÄÍêÕûÃû³Æ£¬ÔÚ DayNames Öж¨Òå¡£
M Ô·ÝÊý×Ö¡£Ò»Î»ÊýµÄÔ·ÝûÓÐÇ°µ¼Áã¡£
MM Ô·ÝÊý×Ö¡£Ò»Î»ÊýµÄÔ·ÝÓÐÒ»¸öÇ°µ¼Áã¡£
MMM Ô·ݵÄËõдÃû³Æ£¬ÔÚ AbbreviatedMonthNames Öж¨Òå¡£
MMMM Ô·ݵÄÍêÕûÃû³Æ£¬ÔÚ MonthNames Öж¨Òå¡£
y ²»°üº¬¼ÍÔªµÄÄê·Ý¡£Èç¹û²»°üº¬¼ÍÔªµÄÄê·ÝСÓÚ 10£¬ÔòÏÔʾ²»¾ßÓÐÇ°µ¼ÁãµÄÄê·Ý¡£
yy ²»°üº¬¼ÍÔªµÄÄê·Ý¡£Èç¹û²»°üº¬¼ÍÔªµÄÄê·ÝСÓÚ 10£¬ÔòÏÔʾ¾ßÓÐÇ°µ¼ÁãµÄÄê·Ý¡£
yyyy °üÀ¨¼ÍÔªµÄËÄλÊýµÄÄê·Ý¡£
gg ʱÆÚ»ò¼ÍÔª¡£Èç¹ûÒªÉèÖøñʽµÄÈÕÆÚ²»¾ßÓйØÁªµÄʱÆÚ»ò¼ÍÔª×Ö·û´®£¬ÔòºöÂÔ¸Ãģʽ¡£
h 12 СʱÖƵÄСʱ¡£Ò»Î»ÊýµÄСʱÊýûÓÐÇ°µ¼Áã¡£
hh 12 СʱÖƵÄСʱ¡£Ò»Î»ÊýµÄСʱÊýÓÐÇ°µ¼Áã¡£
H 24 СʱÖƵÄСʱ¡£Ò»Î»ÊýµÄСʱÊýûÓÐÇ°µ¼Áã¡£
HH 24 СʱÖƵÄСʱ¡£Ò»Î»ÊýµÄСʱÊýÓÐÇ°µ¼Áã¡£
m ·ÖÖÓ¡£Ò»Î»ÊýµÄ·ÖÖÓÊýûÓÐÇ°µ¼Áã¡£
mm ·ÖÖÓ¡£Ò»Î»ÊýµÄ·ÖÖÓÊýÓÐÒ»¸öÇ°µ¼Áã¡£
s Ã롣һλÊýµÄÃëÊýûÓÐÇ°µ¼Áã¡£
ss Ã롣һλÊýµÄÃëÊýÓÐÒ»¸öÇ°µ¼Áã¡£
f ÃëµÄСÊý¾«¶ÈΪһλ¡£ÆäÓàÊý×Ö±»½Ø¶Ï¡£
ff ÃëµÄСÊý¾«¶ÈΪÁ½Î»¡£ÆäÓàÊý×Ö±»½Ø¶Ï¡£
fff ÃëµÄСÊý¾«¶ÈΪÈýλ¡£ÆäÓàÊý×Ö±»½Ø¶Ï¡£
ffff ÃëµÄСÊý¾«¶ÈΪËÄλ¡£ÆäÓàÊý×Ö±»½Ø¶Ï¡£
fffff ÃëµÄСÊý¾«¶ÈΪÎåλ¡£ÆäÓàÊý×Ö±»½Ø¶Ï¡£
ffffff ÃëµÄСÊý¾«¶ÈΪÁùλ¡£ÆäÓàÊý×Ö±»½Ø¶Ï¡£
fffffff ÃëµÄСÊý¾«¶ÈΪÆßλ¡£ÆäÓàÊý×Ö±»½Ø¶Ï¡£
t ÔÚ AMDesignator »ò PMDesignator Öж¨ÒåµÄ AM/PM ָʾÏîµÄµÚÒ»¸ö×Ö·û£¨Èç¹û´æÔÚ£©¡£
tt ÔÚ AMDesignator »ò PMDesignator Öж¨ÒåµÄ AM/PM ָʾÏÈç¹û´æÔÚ£©¡£
z ʱÇøÆ«ÒÆÁ¿£¨¡°+¡±»ò¡°-¡±ºóÃæ½ö¸úСʱ£©¡£Ò»Î»ÊýµÄСʱÊýûÓÐÇ°µ¼Áã¡£ÀýÈ磬̫ƽÑó±ê׼ʱ¼äÊÇ¡°-8¡±¡£
zz ʱÇøÆ«ÒÆÁ¿£¨¡°+¡±»ò¡°-¡±ºóÃæ½ö¸úСʱ£©¡£Ò»Î»ÊýµÄСʱÊýÓÐÇ°µ¼Áã¡£ÀýÈ磬̫ƽÑó±ê׼ʱ¼äÊÇ¡°-08¡±¡£
zzz ÍêÕûʱÇøÆ«ÒÆÁ¿£¨¡°+¡±»ò¡°-¡±ºóÃæ¸úÓÐСʱºÍ·ÖÖÓ£©¡£Ò»Î»ÊýµÄСʱÊýºÍ·ÖÖÓÊýÓÐÇ°µ¼Áã¡£ÀýÈ磬̫ƽÑó±ê׼ʱ¼äÊÇ¡°-08:00¡±¡£
: ÔÚ TimeSeparator Öж¨ÒåµÄĬÈÏʱ¼ä·Ö¸ô·û¡£
/ ÔÚ DateSeparator Öж¨ÒåµÄĬÈÏÈÕÆÚ·Ö¸ô·û¡£
% c ÆäÖÐ c ÊǸñʽģʽ£¨Èç¹ûµ¥¶ÀʹÓã©¡£Èç¹û¸ñʽģʽÓëÔÒå×Ö·û»òÆäËû¸ñʽģʽºÏ²¢£¬Ôò¿ÉÒÔÊ¡ÂÔ¡°%¡±×Ö·û¡£
\ c ÆäÖÐ c ÊÇÈÎÒâ×Ö·û¡£ÕÕÔÒåÏÔʾ×Ö·û¡£ÈôÒªÏÔʾ·´Ð±¸Ü×Ö·û£¬ÇëʹÓá°\\¡±¡£
Ö»ÓÐÉÏÃæµÚ¶þ¸ö±íÖÐÁгöµÄ¸ñʽģʽ²ÅÄÜÓÃÓÚ´´½¨×Ô¶¨Òåģʽ£»ÔÚµÚÒ»¸ö±íÖÐÁгöµÄ±ê×¼¸ñʽ×Ö·û²»ÄÜÓÃÓÚ´´½¨×Ô¶¨Òåģʽ¡£×Ô¶¨ÒåģʽµÄ³¤¶ÈÖÁÉÙΪÁ½¸ö×Ö·û£»ÀýÈ磬
DateTime.ToString( "d") ·µ»Ø DateTime Öµ£»¡°d¡±ÊDZê×¼¶ÌÈÕÆÚģʽ¡£
DateTime.ToString( "%d") ·µ»ØÔÂÖеÄijÌ죻¡°%d¡±ÊÇ×Ô¶¨Òåģʽ¡£
DateTime.ToString( "d ") ·µ»ØºóÃæ¸úÓÐÒ»¸ö¿Õ°××Ö·ûµÄÔÂÖеÄijÌ죻¡°d¡±ÊÇ×Ô¶¨Òåģʽ¡£
±È½Ï·½±ãµÄÊÇ,ÉÏÃæµÄ²ÎÊý¿ÉÒÔËæÒâ×éºÏ,²¢ÇÒ²»»á³ö´í,¶àÊÔÊÔ,¿Ï¶¨»áÕÒµ½ÄãÒªµÄʱ¼ä¸ñʽ
ÈçÒªµÃµ½2005Äê06Ô ÕâÑù¸ñʽµÄʱ¼ä
¿ÉÒÔÕâÑùд:
date.ToString("yyyyÄêMMÔÂ", DateTimeFormatInfo.InvariantInfo)
Èç´ËÀàÍÆ.
ÏÂÃæÁгöһЩAsp.netÖоßÌåµÄÈÕÆÚ¸ñʽ»¯Ó÷¨£º
============================================
1.°ó¶¨Ê±¸ñʽ»¯ÈÕÆÚ·½·¨:
2.Êý¾Ý¿Ø¼þÈçDataGrid/DataListµÈµÄ¼þ¸ñʽ»¯ÈÕÆÚ·½·¨:
e.Item.Cell[0].Text = Convert.ToDateTime(e.Item.Cell[0].Text).ToShortDateString();
3.ÓÃStringÀàת»»ÈÕÆÚÏÔʾ¸ñʽ:
String.Format( "yyyy-MM-dd ",yourDateTime);
4.ÓÃConvert·½·¨×ª»»ÈÕÆÚÏÔʾ¸ñʽ:
Convert.ToDateTime("2005-8-23").ToString
("yyMMdd",System.Globalization.DateTimeFormatInfo.InvariantInfo); //Ö§³Ö·±ÌåÊý¾Ý¿â
5.Ö±½ÓÓÃToString·½·¨×ª»»ÈÕÆÚÏÔʾ¸ñʽ:
DateTime.Now.ToString("yyyyMMddhhmmss");
DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss")
6.Ö»ÏÔʾÄêÔÂ
DataBinder.Eval(Container.DataItem,"starttime","{0:yyyy-M}")
7.ÏÔʾʱ¼äËùÓв¿·Ö£¬°üÀ¨£ºÄêÔÂÈÕʱ·ÖÃë
DataFormatString='{0:yyyy-MM-dd HH24:mm:ss}'>
ÓÃDateTime.ToString(string format)Êä³ö²»Í¬¸ñʽµÄÈÕÆÚ
ת×Ô£ºhttp://www.cnblogs.com/xiaopin/archive/2010/11/05/1870103.html
ÍƼöÐÅÏ¢
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- Asp.net MVCÔ´Âë·ÖÎö--Model Validation(Se....
- .Net À¬»ø»ØÊÕ»úÖÆÔÀíºÍËã·¨£¨Ò»£©
- .netʵÌåнâ
- ·ÖÎöASP.NET¶ÁÈ¡XMLÎļþ4ÖÖ·½·¨
- »ñÈ¡ÍøÕ¾ËõÂÔͼ´úÂë
- Asp.net ¸ù¾ÝIPµØÖ·»ñÈ¡¿çÍø¶ÎmacµØÖ·º¯Êý¡¾ËѲء¿
- ¹ýÂËÃô¸Ð¹Ø¼ü×Ö¡£
- Éú³ÉÖ¸¶¨Î»ÊýµÄËæ»ú×Ö·û´®
- ¿Í»§¶Ë»ñÈ¡MACµØÖ·£¬µ½·þÎñÆ÷ÑéÖ¤
- ²½²½ÎªÓª .NETÈý²ã¼Ü¹¹½âÎö ¶þ¡¢Êý¾Ý¿âÉè¼Æ
ÆÀÂÛ