<%#string.Format(@"<a href=""javascript:void(0);"" onclick=""OpenWindow('{0}');"" title=""{1}"">{1}</a>",Eval("aaa"),Eval("bbb"))%>
这段代码的大体上是把茶连接里的OpenWindow('{0}');替换成OpenWindow('aaa');,title=""{1}""替换成title="bbb",这样么?
关于替换这个答案我找到了,还有就是超链接前面的@是做什么的?
1.对æ´æ°è¿è¡æ ¼å¼åï¼%[index$][æ è¯][æå°å®½åº¦]转æ¢æ¹å¼
æ们å¯ä»¥çå°ï¼æ ¼å¼åå符串ç±4é¨åç»æï¼å ¶ä¸%[index$]çå«ä¹æ们ä¸é¢å·²ç»è®²è¿ï¼[æå°å®½åº¦]çå«ä¹ä¹å¾å¥½ç解ï¼å°±æ¯æç»è¯¥æ´æ°è½¬åçå符串æå°å å«å¤å°ä½æ°åãæ们æ¥ççå©ä¸2个é¨åçå«ä¹å§ï¼
æ è¯ï¼
'-' å¨æå°å®½åº¦å 左对é½ï¼ä¸å¯ä»¥ä¸âç¨0å¡«å âåæ¶ä½¿ç¨
'#' åªéç¨äº8è¿å¶å16è¿å¶ï¼8è¿å¶æ¶å¨ç»æåé¢å¢å ä¸ä¸ª0ï¼16è¿å¶æ¶å¨ç»æåé¢å¢å 0x
'+' ç»ææ»æ¯å æ¬ä¸ä¸ªç¬¦å·ï¼ä¸è¬æ åµä¸åªéç¨äº10è¿å¶ï¼è¥å¯¹è±¡ä¸ºBigIntegeræå¯ä»¥ç¨äº8è¿å¶å16è¿å¶ï¼
' ' æ£å¼åå ç©ºæ ¼ï¼è´å¼åå è´å·ï¼ä¸è¬æ åµä¸åªéç¨äº10è¿å¶ï¼è¥å¯¹è±¡ä¸ºBigIntegeræå¯ä»¥ç¨äº8è¿å¶å16è¿å¶ï¼
'0' ç»æå°ç¨é¶æ¥å¡«å
',' åªéç¨äº10è¿å¶ï¼æ¯3ä½æ°åä¹é´ç¨âï¼âåé
'(' è¥åæ°æ¯è´æ°ï¼åç»æä¸ä¸æ·»å è´å·èæ¯ç¨åæ¬å·ææ°åæ¬èµ·æ¥ï¼åâ+âå ·æåæ ·çéå¶ï¼
转æ¢æ¹å¼ï¼
d-åè¿å¶ o-å «è¿å¶ xæX-åå è¿å¶
ä¸é¢ç说æè¿äºæ¯ç¥ï¼æ们æ¥çå ä¸ªå ·ä½çä¾åãéè¦ç¹å«æ³¨æçä¸ç¹æ¯ï¼å¤§é¨åæ è¯å符å¯ä»¥åæ¶ä½¿ç¨ã
[java] view plain copy
System.out.println(String.format("%1$,09d", -3123));
System.out.println(String.format("%1$9d", -31));
System.out.println(String.format("%1$-9d", -31));
System.out.println(String.format("%1$(9d", -31));
System.out.println(String.format("%1$#9x", 5689));
//ç»æ为ï¼
//-0003,123
// -31
//-31
// (31)
// 0x1639
2.对浮ç¹æ°è¿è¡æ ¼å¼åï¼%[index$][æ è¯][æå°å®½åº¦][.精度]转æ¢æ¹å¼
æ们å¯ä»¥çå°ï¼æµ®ç¹æ°ç转æ¢å¤äºä¸ä¸ªâ精度âé项ï¼å¯ä»¥æ§å¶å°æ°ç¹åé¢çä½æ°ã
æ è¯ï¼
'-' å¨æå°å®½åº¦å 左对é½ï¼ä¸å¯ä»¥ä¸âç¨0å¡«å âåæ¶ä½¿ç¨
'+' ç»ææ»æ¯å æ¬ä¸ä¸ªç¬¦å·
' ' æ£å¼åå ç©ºæ ¼ï¼è´å¼åå è´å·
'0' ç»æå°ç¨é¶æ¥å¡«å
',' æ¯3ä½æ°åä¹é´ç¨âï¼âåéï¼åªéç¨äºfgGç转æ¢ï¼
'(' è¥åæ°æ¯è´æ°ï¼åç»æä¸ä¸æ·»å è´å·èæ¯ç¨åæ¬å·ææ°åæ¬èµ·æ¥ï¼åªéç¨äºeEfgGç转æ¢ï¼
转æ¢æ¹å¼ï¼
'e', 'E' -- ç»æè¢«æ ¼å¼å为ç¨è®¡ç®æºç§å¦è®°æ°æ³è¡¨ç¤ºçåè¿å¶æ°
'f' -- ç»æè¢«æ ¼å¼å为åè¿å¶æ®é表示æ¹å¼
'g', 'G' -- æ ¹æ®å ·ä½æ åµï¼èªå¨éæ©ç¨æ®é表示æ¹å¼è¿æ¯ç§å¦è®¡æ°æ³æ¹å¼
'a', 'A' -- ç»æè¢«æ ¼å¼å为带ææä½æ°åææ°çåå è¿å¶æµ®ç¹æ°
3.对å符è¿è¡æ ¼å¼åï¼
对å符è¿è¡æ ¼å¼åæ¯é常ç®åçï¼c表示å符ï¼æ è¯ä¸'-'表示左对é½ï¼å ¶ä»å°±æ²¡ä»ä¹äºã
4.对ç¾åæ¯ç¬¦å·è¿è¡æ ¼å¼åï¼
çäºä¸é¢ç说æï¼å¤§å®¶ä¼åç°ç¾åæ¯ç¬¦å·â%âæ¯ç¹æ®æ ¼å¼çä¸ä¸ªåç¼ãé£ä¹æ们è¦è¾å ¥ä¸ä¸ªç¾åæ¯ç¬¦å·è¯¥æä¹åå¢ï¼è¯å®æ¯éè¦è½¬ä¹å符ç,ä½æ¯è¦æ³¨æçæ¯ï¼å¨è¿é转ä¹å符ä¸æ¯â\âï¼èæ¯â%âãæ¢å¥è¯è¯´ï¼ä¸é¢è¿æ¡è¯å¥å¯ä»¥è¾åºä¸ä¸ªâ12%âï¼
System.out.println(String.format("%1$d%%", 12));
5.åå¾å¹³å°ç¬ç«çè¡åé符ï¼
System.getProperty("line.separator")å¯ä»¥åå¾å¹³å°ç¬ç«çè¡åé符ï¼ä½æ¯ç¨å¨formatä¸é´æªå æ¾å¾è¿äºç¦çäºãäºæ¯formatå½æ°èªå¸¦äºä¸ä¸ªå¹³å°ç¬ç«çè¡åé符é£å°±æ¯String.format("%n")ã
6.对æ¥æç±»åè¿è¡æ ¼å¼åï¼
以ä¸æ¥æåæ¶é´è½¬æ¢çåç¼å符æ¯ä¸º 't' å 'T' 转æ¢å®ä¹çãè¿äºç±»åç¸ä¼¼äºä½ä¸å®å ¨çåäºé£äºç± GNU date å POSIX strftime(3c) å®ä¹çç±»åãæä¾å ¶ä»è½¬æ¢ç±»åæ¯ä¸ºäºè®¿é®ç¹å®äº Java çåè½ï¼å¦å° 'L' ç¨ä½ç§ä¸ç毫ç§ï¼ã
以ä¸è½¬æ¢å符ç¨æ¥æ ¼å¼åæ¶é´ï¼
'H' 24 å°æ¶å¶çå°æ¶ï¼è¢«æ ¼å¼åä¸ºå¿ è¦æ¶å¸¦å导é¶ç两ä½æ°ï¼å³ 00 - 23ã
'I' 12 å°æ¶å¶çå°æ¶ï¼è¢«æ ¼å¼åä¸ºå¿ è¦æ¶å¸¦å导é¶ç两ä½æ°ï¼å³ 01 - 12ã
'k' 24 å°æ¶å¶çå°æ¶ï¼å³ 0 - 23ã
'l' 12 å°æ¶å¶çå°æ¶ï¼å³ 1 - 12ã
'M' å°æ¶ä¸çåéï¼è¢«æ ¼å¼åä¸ºå¿ è¦æ¶å¸¦å导é¶ç两ä½æ°ï¼å³ 00 - 59ã
'S' åéä¸çç§ï¼è¢«æ ¼å¼åä¸ºå¿ è¦æ¶å¸¦å导é¶ç两ä½æ°ï¼å³ 00 - 60 ï¼"60" æ¯æ¯æé°ç§æéçä¸ä¸ªç¹æ®å¼ï¼ã
'L' ç§ä¸ç毫ç§ï¼è¢«æ ¼å¼åä¸ºå¿ è¦æ¶å¸¦å导é¶çä¸ä½æ°ï¼å³ 000 - 999ã
'N' ç§ä¸ç毫微ç§ï¼è¢«æ ¼å¼åä¸ºå¿ è¦æ¶å¸¦å导é¶çä¹ä½æ°ï¼å³ 000000000 - 999999999ã
'p' ç¹å®äºè¯è¨ç¯å¢ç ä¸åæä¸å æ 记以å°åå½¢å¼è¡¨ç¤ºï¼ä¾å¦ "am" æ "pm"ã使ç¨è½¬æ¢åç¼ 'T' å¯ä»¥å¼ºè¡å°æ¤è¾åºè½¬æ¢ä¸ºå¤§åå½¢å¼ã
'z' ç¸å¯¹äº GMT ç RFC 822 æ ¼å¼çæ°åæ¶åºå移éï¼ä¾å¦ -0800ã
'Z' 表示æ¶åºç¼©åå½¢å¼çå符串ãFormatter çè¯è¨ç¯å¢å°å代åæ°çè¯è¨ç¯å¢ï¼å¦ææï¼ã
's' èªåè°ä¸çæ¶ (UTC) 1970 å¹´ 1 æ 1 æ¥ 00:00:00 è³ç°å¨æç»è¿çç§æ°ï¼å³ Long.MIN_VALUE/1000 ä¸ Long.MAX_VALUE/1000 ä¹é´çå·®å¼ã
'Q' èªåè°ä¸çæ¶ (UTC) 1970 å¹´ 1 æ 1 æ¥ 00:00:00 è³ç°å¨æç»è¿ç毫ç§æ°ï¼å³ Long.MIN_VALUE ä¸ Long.MAX_VALUE ä¹é´çå·®å¼ã
以ä¸è½¬æ¢å符ç¨æ¥æ ¼å¼åæ¥æï¼
'B' ç¹å®äºè¯è¨ç¯å¢çæä»½å ¨ç§°ï¼ä¾å¦ "January" å "February"ã
'b' ç¹å®äºè¯è¨ç¯å¢çæ份ç®ç§°ï¼ä¾å¦ "Jan" å "Feb"ã
'h' ä¸ 'b' ç¸åã
'A' ç¹å®äºè¯è¨ç¯å¢çææå å ¨ç§°ï¼ä¾å¦ "Sunday" å "Monday"
'a' ç¹å®äºè¯è¨ç¯å¢çææå ç®ç§°ï¼ä¾å¦ "Sun" å "Mon"
'C' é¤ä»¥ 100 çåä½æ°è¡¨ç¤ºç年份ï¼è¢«æ ¼å¼åä¸ºå¿ è¦æ¶å¸¦å导é¶ç两ä½æ°ï¼å³ 00 - 99
'Y' 年份ï¼è¢«æ ¼å¼åä¸ºå¿ è¦æ¶å¸¦å导é¶çåä½æ°ï¼è³å°ï¼ï¼ä¾å¦ï¼0092 çäºæ ¼éé«å©åç 92 CEã
'y' 年份çæå两ä½æ°ï¼è¢«æ ¼å¼åä¸ºå¿ è¦æ¶å¸¦å导é¶ç两ä½æ°ï¼å³ 00 - 99ã
'j' ä¸å¹´ä¸ç天æ°ï¼è¢«æ ¼å¼åä¸ºå¿ è¦æ¶å¸¦å导é¶çä¸ä½æ°ï¼ä¾å¦ï¼å¯¹äºæ ¼éé«å©åæ¯ 001 - 366ã
'm' æ份ï¼è¢«æ ¼å¼åä¸ºå¿ è¦æ¶å¸¦å导é¶ç两ä½æ°ï¼å³ 01 - 13ã
'd' ä¸ä¸ªæä¸ç天æ°ï¼è¢«æ ¼å¼åä¸ºå¿ è¦æ¶å¸¦å导é¶ä¸¤ä½æ°ï¼å³ 01 - 31
'e' ä¸ä¸ªæä¸ç天æ°ï¼è¢«æ ¼å¼å为两ä½æ°ï¼å³ 1 - 31ã
以ä¸è½¬æ¢å符ç¨äºæ ¼å¼å常è§çæ¥æ/æ¶é´ç»åã
'R' 24 å°æ¶å¶çæ¶é´ï¼è¢«æ ¼å¼å为 "%tH:%tM"
'T' 24 å°æ¶å¶çæ¶é´ï¼è¢«æ ¼å¼å为 "%tH:%tM:%tS"ã
'r' 12 å°æ¶å¶çæ¶é´ï¼è¢«æ ¼å¼å为 "%tI:%tM:%tS %Tp"ãä¸åæä¸åæ è®° ('%Tp') çä½ç½®å¯è½ä¸è¯è¨ç¯å¢æå ³ã
'D' æ¥æï¼è¢«æ ¼å¼å为 "%tm/%td/%ty"ã
'F' ISO 8601 æ ¼å¼çå®æ´æ¥æï¼è¢«æ ¼å¼å为 "%tY-%tm-%td"ã
'c' æ¥æåæ¶é´ï¼è¢«æ ¼å¼å为 "%ta %tb %td %tT %tZ %tY"ï¼ä¾å¦ "Sun Jul 20 16:17:00 EDT 1969"ã
JDK1.5ä¸ï¼Stringç±»æ°å¢äºä¸ä¸ªå¾æç¨çéææ¹æ³String.format():
format(Locale l, String format, Object... args) 使ç¨æå®çè¯è¨ç¯å¢ãæ ¼å¼å符串ååæ°è¿åä¸ä¸ªæ ¼å¼åå符串ã
format(String format, Object... args) 使ç¨æå®çæ ¼å¼å符串ååæ°è¿åä¸ä¸ªæ ¼å¼åå符串ã
举å 个è¿ä¸ªæ¹æ³å®ç¨çä¾å(注éæ¯è¾åºç»æ)ï¼
CODE:
long now = System.currentTimeMillis();
String s = String.format("%tR", now); // "15:12"
CODE:
// Current month/day/year
Date d = new Date(now);
s = String.format("%tD", d); // "07/13/04"
CODE:
s = String.format("%,d", Integer.MAX_VALUE); // "2,147,483,647"
CODE:
s = String.format("%05d", 123); // "00123"æ¯ä¸æ¯å¾æ¹ä¾¿ï¼è®©äººå¨å¿åï¼ååï¼è¿ææ´å¤çææ!
å ¶å®formatå½æ°æäºç±»ä¼¼Cè¯è¨ä¸printfå½æ°ï¼ä¸äºæ ¼å¼åç¬¦ä¸²ä¸ C 类似ï¼ä½å·²è¿è¡äºæäºå®å¶ï¼ä»¥éåº Java è¯è¨ï¼å¹¶ä¸å©ç¨äºå ¶ä¸ä¸äºç¹æ§ãæ¤æ¹æ³æä¾äºå¯¹å¸å±å¯¹é½åæåçæ¯æï¼ä»¥å对æ°å¼ãå符串åæ¥æ/æ¶é´æ°æ®ç常è§æ ¼å¼åç¹å®äºè¯è¨ç¯å¢çè¾åºçæ¯æãæ¯æè¯¸å¦ byteãBigDecimal å Calendar çå¸¸è§ Java ç±»åã
产çæ ¼å¼åè¾åºçæ¯ä¸ªæ¹æ³é½éè¦æ ¼å¼å符串 ååæ°å表ãæ ¼å¼å符串æ¯ä¸ä¸ª Stringï¼å®å¯ä»¥å å«åºå®ææ¬ä»¥åä¸ä¸ªæå¤ä¸ªåµå ¥çæ ¼å¼è¯´æ符ã请èè以ä¸ç¤ºä¾ï¼
Calendar c = ...;
String s = String.format("Duke's Birthday: %1$tm %1$te,%1$tY", c);
æ ¼å¼åç¬¦ä¸²æ¯ format æ¹æ³ç第ä¸ä¸ªåæ°ãå®å å«ä¸ä¸ªæ ¼å¼è¯´æ符 "%1$tm"ã"%1$te" å "%1$tY"ï¼å®ä»¬æåºåºè¯¥å¦ä½å¤çåæ°ä»¥åå¨ææ¬çä»ä¹å°æ¹æå ¥å®ä»¬ãæ ¼å¼å符串çå ¶ä½é¨åæ¯å æ¬ "Dukes Birthday: " åå ¶ä»ä»»ä½ç©ºæ ¼ææ ç¹ç¬¦å·çåºå®ææ¬ã åæ°å表ç±ä¼ éç»ä½äºæ ¼å¼å符串ä¹åçæ¹æ³çææåæ°ç»æã
å¨ä¸è¿°ç¤ºä¾ä¸ï¼åæ°å表ç大å°ä¸º 1ï¼ç±æ°å¯¹è±¡ Calendar ç»æã
1.常è§ç±»åãå符类ååæ°å¼ç±»åçæ ¼å¼è¯´æ符çè¯æ³å¦ä¸ï¼
%[argument_index$][flags][width][.precision]conversion
å¯éç argument_index æ¯ä¸ä¸ªåè¿å¶æ´æ°ï¼ç¨äºè¡¨æåæ°å¨åæ°å表ä¸çä½ç½®ã第ä¸ä¸ªåæ°ç± "1$" å¼ç¨ï¼ç¬¬äºä¸ªåæ°ç± "2$" å¼ç¨ï¼ä¾æ¤ç±»æ¨ã
å¯éç flags æ¯ä¿®æ¹è¾åºæ ¼å¼çå符éãæææ å¿çéååå³äºè½¬æ¢ç±»åã
å¯é width æ¯ä¸ä¸ªéè´åè¿å¶æ´æ°ï¼è¡¨æè¦åè¾åºä¸åå ¥çæå°å符æ°ã
å¯é precision æ¯ä¸ä¸ªéè´åè¿å¶æ´æ°ï¼é常ç¨æ¥éå¶å符æ°ãç¹å®è¡ä¸ºåå³äºè½¬æ¢ç±»åã
æéç conversion æ¯ä¸ä¸ªè¡¨æåºè¯¥å¦ä½æ ¼å¼ååæ°çå符ãç»å®åæ°çææ转æ¢éååå³äºåæ°çæ°æ®ç±»åã
2.ç¨æ¥è¡¨ç¤ºæ¥æåæ¶é´ç±»åçæ ¼å¼è¯´æ符çè¯æ³å¦ä¸:
%[argument_index$][flags][width]conversion
å¯éç argument_index ãflags å width çå®ä¹åä¸ã
æéç conversion æ¯ä¸ä¸ªç±ä¸¤å符ç»æçåºåã第ä¸ä¸ªåç¬¦æ¯ 't' æ 'T'ã第äºä¸ªå符表ææ使ç¨çæ ¼å¼ãè¿äºå符类似äºä½ä¸å®å ¨çåäºé£äºç± GNU date å POSIX strftime(3c) å®ä¹çå符ã
3.ä¸åæ°ä¸å¯¹åºçæ ¼å¼è¯´æ符çè¯æ³å¦ä¸ï¼
%[flags][width]conversion
å¯é flags å width çå®ä¹åä¸ã
æéç conversion æ¯ä¸ä¸ªè¡¨æè¦å¨è¾åºä¸ææå 容çå符ã
转æ¢
转æ¢å¯å为以ä¸å ç±»ï¼
1. å¸¸è§ - å¯åºç¨äºä»»ä½åæ°ç±»å
2. å符 - å¯åºç¨äºè¡¨ç¤º Unicode å符çåºæ¬ç±»åï¼charãCharacterãbyteãByteãshort å Shortãå½ Character.isValidCodePoint(int) è¿å true æ¶ï¼å¯å°æ¤è½¬æ¢åºç¨äº int å Integer ç±»å
3. æ°å¼
1. æ´æ° - å¯åºç¨äº Java çæ´æ°ç±»åï¼byteãByteãshortãShortãintãIntegerãlongãLong å BigInteger
2. æµ®ç¹ - å¯ç¨äº Java çæµ®ç¹ç±»åï¼floatãFloatãdoubleãDouble å BigDecimal
4. æ¥æ/æ¶é´ - å¯åºç¨äº Java çãè½å¤å¯¹æ¥æææ¶é´è¿è¡ç¼ç çç±»åï¼longãLongãCalendar å Dateã
5. ç¾åæ¯ - 产çåé¢å¼ '%' ('\u0025')
6. è¡åé符 - 产çç¹å®äºå¹³å°çè¡åé符追é®
æ们å¯ä»¥çå°ï¼æ ¼å¼åå符串ç±4é¨åç»æï¼å ¶ä¸%[index$]çå«ä¹æ们ä¸é¢å·²ç»è®²è¿ï¼[æå°å®½åº¦]çå«ä¹ä¹å¾å¥½ç解ï¼å°±æ¯æç»è¯¥æ´æ°è½¬åçå符串æå°å å«å¤å°ä½æ°åãæ们æ¥ççå©ä¸2个é¨åçå«ä¹å§ï¼
æ è¯ï¼
'-' å¨æå°å®½åº¦å 左对é½ï¼ä¸å¯ä»¥ä¸âç¨0å¡«å âåæ¶ä½¿ç¨
'#' åªéç¨äº8è¿å¶å16è¿å¶ï¼8è¿å¶æ¶å¨ç»æåé¢å¢å ä¸ä¸ª0ï¼16è¿å¶æ¶å¨ç»æåé¢å¢å 0x
'+' ç»ææ»æ¯å æ¬ä¸ä¸ªç¬¦å·ï¼ä¸è¬æ åµä¸åªéç¨äº10è¿å¶ï¼è¥å¯¹è±¡ä¸ºBigIntegeræå¯ä»¥ç¨äº8è¿å¶å16è¿å¶ï¼
' ' æ£å¼åå ç©ºæ ¼ï¼è´å¼åå è´å·ï¼ä¸è¬æ åµä¸åªéç¨äº10è¿å¶ï¼è¥å¯¹è±¡ä¸ºBigIntegeræå¯ä»¥ç¨äº8è¿å¶å16è¿å¶ï¼
'0' ç»æå°ç¨é¶æ¥å¡«å
',' åªéç¨äº10è¿å¶ï¼æ¯3ä½æ°åä¹é´ç¨âï¼âåé
'(' è¥åæ°æ¯è´æ°ï¼åç»æä¸ä¸æ·»å è´å·èæ¯ç¨åæ¬å·ææ°åæ¬èµ·æ¥ï¼åâ+âå ·æåæ ·çéå¶ï¼
转æ¢æ¹å¼ï¼
d-åè¿å¶ o-å «è¿å¶ xæX-åå è¿å¶
ä¸é¢ç说æè¿äºæ¯ç¥ï¼æ们æ¥çå ä¸ªå ·ä½çä¾åãéè¦ç¹å«æ³¨æçä¸ç¹æ¯ï¼å¤§é¨åæ è¯å符å¯ä»¥åæ¶ä½¿ç¨ã
[java] view plain copy
System.out.println(String.format("%1$,09d", -3123));
System.out.println(String.format("%1$9d", -31));
System.out.println(String.format("%1$-9d", -31));
System.out.println(String.format("%1$(9d", -31));
System.out.println(String.format("%1$#9x", 5689));
//ç»æ为ï¼
//-0003,123
// -31
//-31
// (31)
// 0x1639
2.对浮ç¹æ°è¿è¡æ ¼å¼åï¼%[index$][æ è¯][æå°å®½åº¦][.精度]转æ¢æ¹å¼
æ们å¯ä»¥çå°ï¼æµ®ç¹æ°ç转æ¢å¤äºä¸ä¸ªâ精度âé项ï¼å¯ä»¥æ§å¶å°æ°ç¹åé¢çä½æ°ã
æ è¯ï¼
'-' å¨æå°å®½åº¦å 左对é½ï¼ä¸å¯ä»¥ä¸âç¨0å¡«å âåæ¶ä½¿ç¨
'+' ç»ææ»æ¯å æ¬ä¸ä¸ªç¬¦å·
' ' æ£å¼åå ç©ºæ ¼ï¼è´å¼åå è´å·
'0' ç»æå°ç¨é¶æ¥å¡«å
',' æ¯3ä½æ°åä¹é´ç¨âï¼âåéï¼åªéç¨äºfgGç转æ¢ï¼
'(' è¥åæ°æ¯è´æ°ï¼åç»æä¸ä¸æ·»å è´å·èæ¯ç¨åæ¬å·ææ°åæ¬èµ·æ¥ï¼åªéç¨äºeEfgGç转æ¢ï¼
转æ¢æ¹å¼ï¼
'e', 'E' -- ç»æè¢«æ ¼å¼å为ç¨è®¡ç®æºç§å¦è®°æ°æ³è¡¨ç¤ºçåè¿å¶æ°
'f' -- ç»æè¢«æ ¼å¼å为åè¿å¶æ®é表示æ¹å¼
'g', 'G' -- æ ¹æ®å ·ä½æ åµï¼èªå¨éæ©ç¨æ®é表示æ¹å¼è¿æ¯ç§å¦è®¡æ°æ³æ¹å¼
'a', 'A' -- ç»æè¢«æ ¼å¼å为带ææä½æ°åææ°çåå è¿å¶æµ®ç¹æ°
3.对å符è¿è¡æ ¼å¼åï¼
对å符è¿è¡æ ¼å¼åæ¯é常ç®åçï¼c表示å符ï¼æ è¯ä¸'-'表示左对é½ï¼å ¶ä»å°±æ²¡ä»ä¹äºã
4.对ç¾åæ¯ç¬¦å·è¿è¡æ ¼å¼åï¼
çäºä¸é¢ç说æï¼å¤§å®¶ä¼åç°ç¾åæ¯ç¬¦å·â%âæ¯ç¹æ®æ ¼å¼çä¸ä¸ªåç¼ãé£ä¹æ们è¦è¾å ¥ä¸ä¸ªç¾åæ¯ç¬¦å·è¯¥æä¹åå¢ï¼è¯å®æ¯éè¦è½¬ä¹å符ç,ä½æ¯è¦æ³¨æçæ¯ï¼å¨è¿é转ä¹å符ä¸æ¯â\âï¼èæ¯â%âãæ¢å¥è¯è¯´ï¼ä¸é¢è¿æ¡è¯å¥å¯ä»¥è¾åºä¸ä¸ªâ12%âï¼
System.out.println(String.format("%1$d%%", 12));
5.åå¾å¹³å°ç¬ç«çè¡åé符ï¼
System.getProperty("line.separator")å¯ä»¥åå¾å¹³å°ç¬ç«çè¡åé符ï¼ä½æ¯ç¨å¨formatä¸é´æªå æ¾å¾è¿äºç¦çäºãäºæ¯formatå½æ°èªå¸¦äºä¸ä¸ªå¹³å°ç¬ç«çè¡åé符é£å°±æ¯String.format("%n")ã
6.对æ¥æç±»åè¿è¡æ ¼å¼åï¼
以ä¸æ¥æåæ¶é´è½¬æ¢çåç¼å符æ¯ä¸º 't' å 'T' 转æ¢å®ä¹çãè¿äºç±»åç¸ä¼¼äºä½ä¸å®å ¨çåäºé£äºç± GNU date å POSIX strftime(3c) å®ä¹çç±»åãæä¾å ¶ä»è½¬æ¢ç±»åæ¯ä¸ºäºè®¿é®ç¹å®äº Java çåè½ï¼å¦å° 'L' ç¨ä½ç§ä¸ç毫ç§ï¼ã
以ä¸è½¬æ¢å符ç¨æ¥æ ¼å¼åæ¶é´ï¼
'H' 24 å°æ¶å¶çå°æ¶ï¼è¢«æ ¼å¼åä¸ºå¿ è¦æ¶å¸¦å导é¶ç两ä½æ°ï¼å³ 00 - 23ã
'I' 12 å°æ¶å¶çå°æ¶ï¼è¢«æ ¼å¼åä¸ºå¿ è¦æ¶å¸¦å导é¶ç两ä½æ°ï¼å³ 01 - 12ã
'k' 24 å°æ¶å¶çå°æ¶ï¼å³ 0 - 23ã
'l' 12 å°æ¶å¶çå°æ¶ï¼å³ 1 - 12ã
'M' å°æ¶ä¸çåéï¼è¢«æ ¼å¼åä¸ºå¿ è¦æ¶å¸¦å导é¶ç两ä½æ°ï¼å³ 00 - 59ã
'S' åéä¸çç§ï¼è¢«æ ¼å¼åä¸ºå¿ è¦æ¶å¸¦å导é¶ç两ä½æ°ï¼å³ 00 - 60 ï¼"60" æ¯æ¯æé°ç§æéçä¸ä¸ªç¹æ®å¼ï¼ã
'L' ç§ä¸ç毫ç§ï¼è¢«æ ¼å¼åä¸ºå¿ è¦æ¶å¸¦å导é¶çä¸ä½æ°ï¼å³ 000 - 999ã
'N' ç§ä¸ç毫微ç§ï¼è¢«æ ¼å¼åä¸ºå¿ è¦æ¶å¸¦å导é¶çä¹ä½æ°ï¼å³ 000000000 - 999999999ã
'p' ç¹å®äºè¯è¨ç¯å¢ç ä¸åæä¸å æ 记以å°åå½¢å¼è¡¨ç¤ºï¼ä¾å¦ "am" æ "pm"ã使ç¨è½¬æ¢åç¼ 'T' å¯ä»¥å¼ºè¡å°æ¤è¾åºè½¬æ¢ä¸ºå¤§åå½¢å¼ã
'z' ç¸å¯¹äº GMT ç RFC 822 æ ¼å¼çæ°åæ¶åºå移éï¼ä¾å¦ -0800ã
'Z' 表示æ¶åºç¼©åå½¢å¼çå符串ãFormatter çè¯è¨ç¯å¢å°å代åæ°çè¯è¨ç¯å¢ï¼å¦ææï¼ã
's' èªåè°ä¸çæ¶ (UTC) 1970 å¹´ 1 æ 1 æ¥ 00:00:00 è³ç°å¨æç»è¿çç§æ°ï¼å³ Long.MIN_VALUE/1000 ä¸ Long.MAX_VALUE/1000 ä¹é´çå·®å¼ã
'Q' èªåè°ä¸çæ¶ (UTC) 1970 å¹´ 1 æ 1 æ¥ 00:00:00 è³ç°å¨æç»è¿ç毫ç§æ°ï¼å³ Long.MIN_VALUE ä¸ Long.MAX_VALUE ä¹é´çå·®å¼ã
以ä¸è½¬æ¢å符ç¨æ¥æ ¼å¼åæ¥æï¼
'B' ç¹å®äºè¯è¨ç¯å¢çæä»½å ¨ç§°ï¼ä¾å¦ "January" å "February"ã
'b' ç¹å®äºè¯è¨ç¯å¢çæ份ç®ç§°ï¼ä¾å¦ "Jan" å "Feb"ã
'h' ä¸ 'b' ç¸åã
'A' ç¹å®äºè¯è¨ç¯å¢çææå å ¨ç§°ï¼ä¾å¦ "Sunday" å "Monday"
'a' ç¹å®äºè¯è¨ç¯å¢çææå ç®ç§°ï¼ä¾å¦ "Sun" å "Mon"
'C' é¤ä»¥ 100 çåä½æ°è¡¨ç¤ºç年份ï¼è¢«æ ¼å¼åä¸ºå¿ è¦æ¶å¸¦å导é¶ç两ä½æ°ï¼å³ 00 - 99
'Y' 年份ï¼è¢«æ ¼å¼åä¸ºå¿ è¦æ¶å¸¦å导é¶çåä½æ°ï¼è³å°ï¼ï¼ä¾å¦ï¼0092 çäºæ ¼éé«å©åç 92 CEã
'y' 年份çæå两ä½æ°ï¼è¢«æ ¼å¼åä¸ºå¿ è¦æ¶å¸¦å导é¶ç两ä½æ°ï¼å³ 00 - 99ã
'j' ä¸å¹´ä¸ç天æ°ï¼è¢«æ ¼å¼åä¸ºå¿ è¦æ¶å¸¦å导é¶çä¸ä½æ°ï¼ä¾å¦ï¼å¯¹äºæ ¼éé«å©åæ¯ 001 - 366ã
'm' æ份ï¼è¢«æ ¼å¼åä¸ºå¿ è¦æ¶å¸¦å导é¶ç两ä½æ°ï¼å³ 01 - 13ã
'd' ä¸ä¸ªæä¸ç天æ°ï¼è¢«æ ¼å¼åä¸ºå¿ è¦æ¶å¸¦å导é¶ä¸¤ä½æ°ï¼å³ 01 - 31
'e' ä¸ä¸ªæä¸ç天æ°ï¼è¢«æ ¼å¼å为两ä½æ°ï¼å³ 1 - 31ã
以ä¸è½¬æ¢å符ç¨äºæ ¼å¼å常è§çæ¥æ/æ¶é´ç»åã
'R' 24 å°æ¶å¶çæ¶é´ï¼è¢«æ ¼å¼å为 "%tH:%tM"
'T' 24 å°æ¶å¶çæ¶é´ï¼è¢«æ ¼å¼å为 "%tH:%tM:%tS"ã
'r' 12 å°æ¶å¶çæ¶é´ï¼è¢«æ ¼å¼å为 "%tI:%tM:%tS %Tp"ãä¸åæä¸åæ è®° ('%Tp') çä½ç½®å¯è½ä¸è¯è¨ç¯å¢æå ³ã
'D' æ¥æï¼è¢«æ ¼å¼å为 "%tm/%td/%ty"ã
'F' ISO 8601 æ ¼å¼çå®æ´æ¥æï¼è¢«æ ¼å¼å为 "%tY-%tm-%td"ã
'c' æ¥æåæ¶é´ï¼è¢«æ ¼å¼å为 "%ta %tb %td %tT %tZ %tY"ï¼ä¾å¦ "Sun Jul 20 16:17:00 EDT 1969"ã
JDK1.5ä¸ï¼Stringç±»æ°å¢äºä¸ä¸ªå¾æç¨çéææ¹æ³String.format():
format(Locale l, String format, Object... args) 使ç¨æå®çè¯è¨ç¯å¢ãæ ¼å¼å符串ååæ°è¿åä¸ä¸ªæ ¼å¼åå符串ã
format(String format, Object... args) 使ç¨æå®çæ ¼å¼å符串ååæ°è¿åä¸ä¸ªæ ¼å¼åå符串ã
举å 个è¿ä¸ªæ¹æ³å®ç¨çä¾å(注éæ¯è¾åºç»æ)ï¼
CODE:
long now = System.currentTimeMillis();
String s = String.format("%tR", now); // "15:12"
CODE:
// Current month/day/year
Date d = new Date(now);
s = String.format("%tD", d); // "07/13/04"
CODE:
s = String.format("%,d", Integer.MAX_VALUE); // "2,147,483,647"
CODE:
s = String.format("%05d", 123); // "00123"æ¯ä¸æ¯å¾æ¹ä¾¿ï¼è®©äººå¨å¿åï¼ååï¼è¿ææ´å¤çææ!
å ¶å®formatå½æ°æäºç±»ä¼¼Cè¯è¨ä¸printfå½æ°ï¼ä¸äºæ ¼å¼åç¬¦ä¸²ä¸ C 类似ï¼ä½å·²è¿è¡äºæäºå®å¶ï¼ä»¥éåº Java è¯è¨ï¼å¹¶ä¸å©ç¨äºå ¶ä¸ä¸äºç¹æ§ãæ¤æ¹æ³æä¾äºå¯¹å¸å±å¯¹é½åæåçæ¯æï¼ä»¥å对æ°å¼ãå符串åæ¥æ/æ¶é´æ°æ®ç常è§æ ¼å¼åç¹å®äºè¯è¨ç¯å¢çè¾åºçæ¯æãæ¯æè¯¸å¦ byteãBigDecimal å Calendar çå¸¸è§ Java ç±»åã
产çæ ¼å¼åè¾åºçæ¯ä¸ªæ¹æ³é½éè¦æ ¼å¼å符串 ååæ°å表ãæ ¼å¼å符串æ¯ä¸ä¸ª Stringï¼å®å¯ä»¥å å«åºå®ææ¬ä»¥åä¸ä¸ªæå¤ä¸ªåµå ¥çæ ¼å¼è¯´æ符ã请èè以ä¸ç¤ºä¾ï¼
Calendar c = ...;
String s = String.format("Duke's Birthday: %1$tm %1$te,%1$tY", c);
æ ¼å¼åç¬¦ä¸²æ¯ format æ¹æ³ç第ä¸ä¸ªåæ°ãå®å å«ä¸ä¸ªæ ¼å¼è¯´æ符 "%1$tm"ã"%1$te" å "%1$tY"ï¼å®ä»¬æåºåºè¯¥å¦ä½å¤çåæ°ä»¥åå¨ææ¬çä»ä¹å°æ¹æå ¥å®ä»¬ãæ ¼å¼å符串çå ¶ä½é¨åæ¯å æ¬ "Dukes Birthday: " åå ¶ä»ä»»ä½ç©ºæ ¼ææ ç¹ç¬¦å·çåºå®ææ¬ã åæ°å表ç±ä¼ éç»ä½äºæ ¼å¼å符串ä¹åçæ¹æ³çææåæ°ç»æã
å¨ä¸è¿°ç¤ºä¾ä¸ï¼åæ°å表ç大å°ä¸º 1ï¼ç±æ°å¯¹è±¡ Calendar ç»æã
1.常è§ç±»åãå符类ååæ°å¼ç±»åçæ ¼å¼è¯´æ符çè¯æ³å¦ä¸ï¼
%[argument_index$][flags][width][.precision]conversion
å¯éç argument_index æ¯ä¸ä¸ªåè¿å¶æ´æ°ï¼ç¨äºè¡¨æåæ°å¨åæ°å表ä¸çä½ç½®ã第ä¸ä¸ªåæ°ç± "1$" å¼ç¨ï¼ç¬¬äºä¸ªåæ°ç± "2$" å¼ç¨ï¼ä¾æ¤ç±»æ¨ã
å¯éç flags æ¯ä¿®æ¹è¾åºæ ¼å¼çå符éãæææ å¿çéååå³äºè½¬æ¢ç±»åã
å¯é width æ¯ä¸ä¸ªéè´åè¿å¶æ´æ°ï¼è¡¨æè¦åè¾åºä¸åå ¥çæå°å符æ°ã
å¯é precision æ¯ä¸ä¸ªéè´åè¿å¶æ´æ°ï¼é常ç¨æ¥éå¶å符æ°ãç¹å®è¡ä¸ºåå³äºè½¬æ¢ç±»åã
æéç conversion æ¯ä¸ä¸ªè¡¨æåºè¯¥å¦ä½æ ¼å¼ååæ°çå符ãç»å®åæ°çææ转æ¢éååå³äºåæ°çæ°æ®ç±»åã
2.ç¨æ¥è¡¨ç¤ºæ¥æåæ¶é´ç±»åçæ ¼å¼è¯´æ符çè¯æ³å¦ä¸:
%[argument_index$][flags][width]conversion
å¯éç argument_index ãflags å width çå®ä¹åä¸ã
æéç conversion æ¯ä¸ä¸ªç±ä¸¤å符ç»æçåºåã第ä¸ä¸ªåç¬¦æ¯ 't' æ 'T'ã第äºä¸ªå符表ææ使ç¨çæ ¼å¼ãè¿äºå符类似äºä½ä¸å®å ¨çåäºé£äºç± GNU date å POSIX strftime(3c) å®ä¹çå符ã
3.ä¸åæ°ä¸å¯¹åºçæ ¼å¼è¯´æ符çè¯æ³å¦ä¸ï¼
%[flags][width]conversion
å¯é flags å width çå®ä¹åä¸ã
æéç conversion æ¯ä¸ä¸ªè¡¨æè¦å¨è¾åºä¸ææå 容çå符ã
转æ¢
转æ¢å¯å为以ä¸å ç±»ï¼
1. å¸¸è§ - å¯åºç¨äºä»»ä½åæ°ç±»å
2. å符 - å¯åºç¨äºè¡¨ç¤º Unicode å符çåºæ¬ç±»åï¼charãCharacterãbyteãByteãshort å Shortãå½ Character.isValidCodePoint(int) è¿å true æ¶ï¼å¯å°æ¤è½¬æ¢åºç¨äº int å Integer ç±»å
3. æ°å¼
1. æ´æ° - å¯åºç¨äº Java çæ´æ°ç±»åï¼byteãByteãshortãShortãintãIntegerãlongãLong å BigInteger
2. æµ®ç¹ - å¯ç¨äº Java çæµ®ç¹ç±»åï¼floatãFloatãdoubleãDouble å BigDecimal
4. æ¥æ/æ¶é´ - å¯åºç¨äº Java çãè½å¤å¯¹æ¥æææ¶é´è¿è¡ç¼ç çç±»åï¼longãLongãCalendar å Dateã
5. ç¾åæ¯ - 产çåé¢å¼ '%' ('\u0025')
6. è¡åé符 - 产çç¹å®äºå¹³å°çè¡åé符追é®
大å¥ï¼ä½ çåçå¨åªécopyçï¼
=================以ä¸ç¬¬ä¸æ¬¡è¿½é®
è¿ç§ææ¯ææ³è¦çï¼è¿æå°±æ¯é£éé¢è¶ é¾æ¥åé¢ç@æ¯ä½ä»ä¹ç¨çï¼
============以ä¸ç¬¬äºæ¬¡è¿½é®
好å§@çä½ç¨æä¹ç¥éäºæ¯è½¬ä¹çä½ç¨ï¼åæ£å°±ä½ èªå·±çäºå°±ç»ä½ å§
============以ä¸ç¬¬ä¸æ¬¡è¿½é®
温馨提示:答案为网友推荐,仅供参考
第1个回答 2018-12-28
hx,,cvrz@,vvv }X, g b dx,cvgsdd@,V V z