- 浏览: 210524 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (166)
- Hibernate (3)
- Spring (18)
- Struts (1)
- Grails (0)
- Tools (17)
- j2se (17)
- webservice (3)
- js (5)
- XML (5)
- apache (6)
- JavaWeb (2)
- oracle (5)
- plan (12)
- linux (5)
- FreeMarker (3)
- maven (5)
- Activiti (4)
- log4jdbc (1)
- self4j (1)
- log4j (1)
- j2ee (1)
- shiro (2)
- MySQL (4)
- reflect (2)
- cmd (1)
- DB (6)
- report (1)
- jQuery (1)
- Cache (4)
- MQ (2)
- NIO (1)
- SCM (1)
- Framework (2)
- computer (2)
- MyBatis (1)
- cluster (1)
- solr (13)
- ZooKeeper (1)
- SVN (1)
- http (0)
- websocket (1)
- Tomcat (2)
- Spring Remote (2)
- Android (1)
- dubbo (1)
最新评论
-
whuvr:
import com.capitalbio.soft.core ...
Jedis+SpringDataRedis+Spring -
tianlanxing:
方法 不对 博主赶紧删了
SpringMVC中获取request与response对象 -
xiaoliu128:
汗。写了一大堆,没看出来是怎么数据库配置权限
shiro拦截url动态配置在数据库 -
javajiangyijin:
你好!按照你说的这样,/** 获取HttpServletRes ...
SpringMVC中获取request与response对象 -
虎踞龙盘忆江南:
你有个地方写的有点问题! appPat ...
Web项目的自定义属性配置文件读取- Windows/Linux
JDK: java.util.Formatter.Conversion 类:
格式化代码:
JDK HELP:
Conversion Argument Category Description
'b', 'B' general If the argument arg is null, then the result is "false". If arg is a boolean or Boolean, then the result is the string returned by String.valueOf(). Otherwise, the result is "true".
'h', 'H' general If the argument arg is null, then the result is "null". Otherwise, the result is obtained by invoking Integer.toHexString(arg.hashCode()).
's', 'S' general If the argument arg is null, then the result is "null". If arg implements Formattable, then arg.formatTo is invoked. Otherwise, the result is obtained by invoking arg.toString().
'c', 'C' character The result is a Unicode character
'd' integral The result is formatted as a decimal integer
'o' integral The result is formatted as an octal integer
'x', 'X' integral The result is formatted as a hexadecimal integer
'e', 'E' floating point The result is formatted as a decimal number in computerized scientific notation
'f' floating point The result is formatted as a decimal number
'g', 'G' floating point The result is formatted using computerized scientific notation or decimal format, depending on the precision and the value after rounding.
'a', 'A' floating point The result is formatted as a hexadecimal floating-point number with a significand and an exponent
't', 'T' date/time Prefix for date and time conversion characters. See Date/Time Conversions.
'%' percent The result is a literal '%' ('\u0025')
'n' line separator The result is the platform-specific line separator
Any characters not explicitly defined as conversions are illegal and are reserved for future extensions.
Date/Time Conversions
The following date and time conversion suffix characters are defined for the 't' and 'T' conversions. The types are similar to but not completely identical to those defined by GNU date and POSIX strftime(3c). Additional conversion types are provided to access Java-specific functionality (e.g. 'L' for milliseconds within the second).
The following conversion characters are used for formatting times: 'H' Hour of the day for the 24-hour clock, formatted as two digits with a leading zero as necessary i.e. 00 - 23.
'I' Hour for the 12-hour clock, formatted as two digits with a leading zero as necessary, i.e. 01 - 12.
'k' Hour of the day for the 24-hour clock, i.e. 0 - 23.
'l' Hour for the 12-hour clock, i.e. 1 - 12.
'M' Minute within the hour formatted as two digits with a leading zero as necessary, i.e. 00 - 59.
'S' Seconds within the minute, formatted as two digits with a leading zero as necessary, i.e. 00 - 60 ("60" is a special value required to support leap seconds).
'L' Millisecond within the second formatted as three digits with leading zeros as necessary, i.e. 000 - 999.
'N' Nanosecond within the second, formatted as nine digits with leading zeros as necessary, i.e. 000000000 - 999999999.
'p' Locale-specific morning or afternoon marker in lower case, e.g."am" or "pm". Use of the conversion prefix 'T' forces this output to upper case.
'z' RFC 822 style numeric time zone offset from GMT, e.g. -0800.
'Z' A string representing the abbreviation for the time zone. The Formatter's locale will supersede the locale of the argument (if any).
's' Seconds since the beginning of the epoch starting at 1 January 1970 00:00:00 UTC, i.e. Long.MIN_VALUE/1000 to Long.MAX_VALUE/1000.
'Q' Milliseconds since the beginning of the epoch starting at 1 January 1970 00:00:00 UTC, i.e. Long.MIN_VALUE to Long.MAX_VALUE.
The following conversion characters are used for formatting dates: 'B' Locale-specific full month name, e.g. "January", "February".
'b' Locale-specific abbreviated month name, e.g. "Jan", "Feb".
'h' Same as 'b'.
'A' Locale-specific full name of the day of the week, e.g. "Sunday", "Monday"
'a' Locale-specific short name of the day of the week, e.g. "Sun", "Mon"
'C' Four-digit year divided by 100, formatted as two digits with leading zero as necessary, i.e. 00 - 99
'Y' Year, formatted as at least four digits with leading zeros as necessary, e.g. 0092 equals 92 CE for the Gregorian calendar.
'y' Last two digits of the year, formatted with leading zeros as necessary, i.e. 00 - 99.
'j' Day of year, formatted as three digits with leading zeros as necessary, e.g. 001 - 366 for the Gregorian calendar.
'm' Month, formatted as two digits with leading zeros as necessary, i.e. 01 - 13.
'd' Day of month, formatted as two digits with leading zeros as necessary, i.e. 01 - 31
'e' Day of month, formatted as two digits, i.e. 1 - 31.
The following conversion characters are used for formatting common date/time compositions. 'R' Time formatted for the 24-hour clock as "%tH:%tM"
'T' Time formatted for the 24-hour clock as "%tH:%tM:%tS".
'r' Time formatted for the 12-hour clock as "%tI:%tM:%tS %Tp". The location of the morning or afternoon marker ('%Tp') may be locale-dependent.
'D' Date formatted as "%tm/%td/%ty".
'F' ISO 8601 complete date formatted as "%tY-%tm-%td".
'c' Date and time formatted as "%ta %tb %td %tT %tZ %tY", e.g. "Sun Jul 20 16:17:00 EDT 1969".
Any characters not explicitly defined as date/time conversion suffixes are illegal and are reserved for future extensions
private static class Conversion { // Byte, Short, Integer, Long, BigInteger // (and associated primitives due to autoboxing) static final char DECIMAL_INTEGER = 'd'; static final char OCTAL_INTEGER = 'o'; static final char HEXADECIMAL_INTEGER = 'x'; static final char HEXADECIMAL_INTEGER_UPPER = 'X'; // Float, Double, BigDecimal // (and associated primitives due to autoboxing) static final char SCIENTIFIC = 'e'; static final char SCIENTIFIC_UPPER = 'E'; static final char GENERAL = 'g'; static final char GENERAL_UPPER = 'G'; static final char DECIMAL_FLOAT = 'f'; static final char HEXADECIMAL_FLOAT = 'a'; static final char HEXADECIMAL_FLOAT_UPPER = 'A'; // Character, Byte, Short, Integer // (and associated primitives due to autoboxing) static final char CHARACTER = 'c'; static final char CHARACTER_UPPER = 'C'; // java.util.Date, java.util.Calendar, long static final char DATE_TIME = 't'; static final char DATE_TIME_UPPER = 'T'; // if (arg.TYPE != boolean) return boolean // if (arg != null) return true; else return false; static final char BOOLEAN = 'b'; static final char BOOLEAN_UPPER = 'B'; // if (arg instanceof Formattable) arg.formatTo() // else arg.toString(); static final char STRING = 's'; static final char STRING_UPPER = 'S'; // arg.hashCode() static final char HASHCODE = 'h'; static final char HASHCODE_UPPER = 'H'; static final char LINE_SEPARATOR = 'n'; static final char PERCENT_SIGN = '%'; static boolean isValid(char c) { return (isGeneral(c) || isInteger(c) || isFloat(c) || isText(c) || c == 't' || isCharacter(c)); }
格式化代码:
public class TestString { public static void main(String[] args) { String repStr = "hello"; int repInt = 33; double repNo = 21.22; String configStr = "%s world %d %f"; String ret = String.format(configStr, repStr,repInt,repNo); System.out.println(ret); } }
JDK HELP:
Conversion Argument Category Description
'b', 'B' general If the argument arg is null, then the result is "false". If arg is a boolean or Boolean, then the result is the string returned by String.valueOf(). Otherwise, the result is "true".
'h', 'H' general If the argument arg is null, then the result is "null". Otherwise, the result is obtained by invoking Integer.toHexString(arg.hashCode()).
's', 'S' general If the argument arg is null, then the result is "null". If arg implements Formattable, then arg.formatTo is invoked. Otherwise, the result is obtained by invoking arg.toString().
'c', 'C' character The result is a Unicode character
'd' integral The result is formatted as a decimal integer
'o' integral The result is formatted as an octal integer
'x', 'X' integral The result is formatted as a hexadecimal integer
'e', 'E' floating point The result is formatted as a decimal number in computerized scientific notation
'f' floating point The result is formatted as a decimal number
'g', 'G' floating point The result is formatted using computerized scientific notation or decimal format, depending on the precision and the value after rounding.
'a', 'A' floating point The result is formatted as a hexadecimal floating-point number with a significand and an exponent
't', 'T' date/time Prefix for date and time conversion characters. See Date/Time Conversions.
'%' percent The result is a literal '%' ('\u0025')
'n' line separator The result is the platform-specific line separator
Any characters not explicitly defined as conversions are illegal and are reserved for future extensions.
Date/Time Conversions
The following date and time conversion suffix characters are defined for the 't' and 'T' conversions. The types are similar to but not completely identical to those defined by GNU date and POSIX strftime(3c). Additional conversion types are provided to access Java-specific functionality (e.g. 'L' for milliseconds within the second).
The following conversion characters are used for formatting times: 'H' Hour of the day for the 24-hour clock, formatted as two digits with a leading zero as necessary i.e. 00 - 23.
'I' Hour for the 12-hour clock, formatted as two digits with a leading zero as necessary, i.e. 01 - 12.
'k' Hour of the day for the 24-hour clock, i.e. 0 - 23.
'l' Hour for the 12-hour clock, i.e. 1 - 12.
'M' Minute within the hour formatted as two digits with a leading zero as necessary, i.e. 00 - 59.
'S' Seconds within the minute, formatted as two digits with a leading zero as necessary, i.e. 00 - 60 ("60" is a special value required to support leap seconds).
'L' Millisecond within the second formatted as three digits with leading zeros as necessary, i.e. 000 - 999.
'N' Nanosecond within the second, formatted as nine digits with leading zeros as necessary, i.e. 000000000 - 999999999.
'p' Locale-specific morning or afternoon marker in lower case, e.g."am" or "pm". Use of the conversion prefix 'T' forces this output to upper case.
'z' RFC 822 style numeric time zone offset from GMT, e.g. -0800.
'Z' A string representing the abbreviation for the time zone. The Formatter's locale will supersede the locale of the argument (if any).
's' Seconds since the beginning of the epoch starting at 1 January 1970 00:00:00 UTC, i.e. Long.MIN_VALUE/1000 to Long.MAX_VALUE/1000.
'Q' Milliseconds since the beginning of the epoch starting at 1 January 1970 00:00:00 UTC, i.e. Long.MIN_VALUE to Long.MAX_VALUE.
The following conversion characters are used for formatting dates: 'B' Locale-specific full month name, e.g. "January", "February".
'b' Locale-specific abbreviated month name, e.g. "Jan", "Feb".
'h' Same as 'b'.
'A' Locale-specific full name of the day of the week, e.g. "Sunday", "Monday"
'a' Locale-specific short name of the day of the week, e.g. "Sun", "Mon"
'C' Four-digit year divided by 100, formatted as two digits with leading zero as necessary, i.e. 00 - 99
'Y' Year, formatted as at least four digits with leading zeros as necessary, e.g. 0092 equals 92 CE for the Gregorian calendar.
'y' Last two digits of the year, formatted with leading zeros as necessary, i.e. 00 - 99.
'j' Day of year, formatted as three digits with leading zeros as necessary, e.g. 001 - 366 for the Gregorian calendar.
'm' Month, formatted as two digits with leading zeros as necessary, i.e. 01 - 13.
'd' Day of month, formatted as two digits with leading zeros as necessary, i.e. 01 - 31
'e' Day of month, formatted as two digits, i.e. 1 - 31.
The following conversion characters are used for formatting common date/time compositions. 'R' Time formatted for the 24-hour clock as "%tH:%tM"
'T' Time formatted for the 24-hour clock as "%tH:%tM:%tS".
'r' Time formatted for the 12-hour clock as "%tI:%tM:%tS %Tp". The location of the morning or afternoon marker ('%Tp') may be locale-dependent.
'D' Date formatted as "%tm/%td/%ty".
'F' ISO 8601 complete date formatted as "%tY-%tm-%td".
'c' Date and time formatted as "%ta %tb %td %tT %tZ %tY", e.g. "Sun Jul 20 16:17:00 EDT 1969".
Any characters not explicitly defined as date/time conversion suffixes are illegal and are reserved for future extensions
发表评论
-
Socket编程之TCP/UDP
2015-03-13 20:46 6361: TCP编程(一对多): 服务器端: p ... -
java.util.ResourceBundle
2014-12-29 14:17 5121:用法: ResourceBundle bundl ... -
JDK Proxy使用
2014-12-17 14:51 5361: 使用JDK Proxy 进行动态拦截某个类的方法执行 ... -
递归拷贝/删除文件/文件夹:
2014-07-23 10:54 601递归拷贝/删除文件/文件夹: package cn.sy ... -
JDK无法通过环境变量切换问题
2014-07-22 11:19 448当指定JDK环境变量但是还是无法根据环境变量找到指定的 ... -
MIME type 映射
2013-04-19 12:39 676323=text/h323 acx=applicatio ... -
Java获取当前运行方法的名称
2013-04-08 17:02 634方法一:new Exception().getStackTr ... -
java按长度生成随机数字和字母组合
2012-09-20 11:46 1107import java.util.Random; pub ... -
基于反射_判断子类泛型类型
2012-05-25 21:12 1168父类代码: package cn.generic ... -
ProxyPattern_代理模式
2012-01-01 20:15 7981:此例演示 使用JDK代理模式,使用此模式须实现接口,对没有 ... -
Java_设置HTTP代理
2011-12-12 16:54 800/**如果有代理设置所使用 * @param hos ... -
JAX-WS_Java API for XML Web Services
2011-11-04 16:15 11361:写出WebService 实现类: package c ... -
JAXB_Java Architecture For XML Binding
2011-11-03 16:03 10461:写好XML文件且根据XML文件写出XSD文件: (或者使 ... -
java 命令
2011-08-19 16:26 728主要介绍java和javac命令的使用,分带package和不 ... -
Date and Time Format Patterns
2011-08-02 18:47 769Date and Time Format Patterns ... -
通过url下载文件到本地
2011-08-01 09:39 23491:通过URL下载文件: public class Dow ...
相关推荐
java字符串格式化String.format()
NULL 博文链接:https://xuanzhui.iteye.com/blog/2263267
json字符串格式化工具
json字符串格式化工具,不用安装,直接运行,美化json字符串,方便,快捷。json字符串格式化工具,不用安装,直接运行,美化json字符串,方便,快捷。json字符串格式化工具,不用安装,直接运行,美化json字符串,...
java 字符串 详细实例代码 字符串检索 可改变字符串 字符串生成器 日期和时间字符串格式化
Java_格式化字符串 很全的,常用的都包括了。
JDK1.5中,String类新增了一个很有用的静态方法,这些方法有助于开发人员对字符串的各类操作
Java字符串 日期 数字格式化输出.docJava字符串 日期 数字格式化输出.docJava字符串 日期 数字格式化输出.docJava字符串 日期 数字格式化输出.docJava字符串 日期 数字格式化输出.docJava字符串 日期 数字格式化输出...
HiJson工具免去了我们需要联网格式化json字符串的烦恼,无需百度搜索在线格式化,只要安装了JDK,打开就可以用。
本篇文章主要介绍了JAVA字符串格式化-String.format()的使用,具有一定的参考价值,有需要的可以了解一下。
java代码-使用java解决json字符串格式化的源代码 ——学习参考资料:仅用于个人学习使用!
json数据交互时作为校验是否通过,用于后台需要构建json返回前台必备
java
按格式化字符串将 String 类型 转换为 sql.date 注意,非 util.date 可视化字符串例如 "yyyy-MM-dd HH:mm:ss
运用JAVAScript自定义函数,实现数字字符的格式化转换,在实际网站开发中,有很多地方可以适用,不难却很实用。
Java 实例 - 字符串格式化源代码-详细教程.zip
Java字符串_日期_数字格式化输出,特别适合初学者了解各个数据类型的操作和应用。
从Hibernate中提取的SQL格式化功能,去除了没用的功能,没有第三方jar包
Java Swing GUI桌面应用工具,集成常用的开发调试工具。...2、Unix时间戳,获取最新时间,Unix时间戳转化为通用时间字符串格式 3、字符串长度计算 4、Url编码 解码 5、Base64 加密 解密 6、Unicode 编码 解码
auto-string-formatter是Java的字符串格式化库,可在编译时通过注释处理生成优化的formatter方法。 auto-string-formatter具有以下功能: 使用StringBuilder就像手写代码一样快。 (大多数)兼容String.format 。...