- 浏览: 216027 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (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 6661: TCP编程(一对多): 服务器端: p ... -
java.util.ResourceBundle
2014-12-29 14:17 5411:用法: ResourceBundle bundl ... -
JDK Proxy使用
2014-12-17 14:51 5691: 使用JDK Proxy 进行动态拦截某个类的方法执行 ... -
递归拷贝/删除文件/文件夹:
2014-07-23 10:54 626递归拷贝/删除文件/文件夹: package cn.sy ... -
JDK无法通过环境变量切换问题
2014-07-22 11:19 489当指定JDK环境变量但是还是无法根据环境变量找到指定的 ... -
MIME type 映射
2013-04-19 12:39 700323=text/h323 acx=applicatio ... -
Java获取当前运行方法的名称
2013-04-08 17:02 664方法一:new Exception().getStackTr ... -
java按长度生成随机数字和字母组合
2012-09-20 11:46 1145import java.util.Random; pub ... -
基于反射_判断子类泛型类型
2012-05-25 21:12 1199父类代码: package cn.generic ... -
ProxyPattern_代理模式
2012-01-01 20:15 8201:此例演示 使用JDK代理模式,使用此模式须实现接口,对没有 ... -
Java_设置HTTP代理
2011-12-12 16:54 830/**如果有代理设置所使用 * @param hos ... -
JAX-WS_Java API for XML Web Services
2011-11-04 16:15 11621:写出WebService 实现类: package c ... -
JAXB_Java Architecture For XML Binding
2011-11-03 16:03 10981:写好XML文件且根据XML文件写出XSD文件: (或者使 ... -
java 命令
2011-08-19 16:26 752主要介绍java和javac命令的使用,分带package和不 ... -
Date and Time Format Patterns
2011-08-02 18:47 799Date and Time Format Patterns ... -
通过url下载文件到本地
2011-08-01 09:39 23841:通过URL下载文件: public class Dow ...
相关推荐
总结来说,Java字符串格式化是构建和展示文本信息的关键技术,包括使用`String.format()`和`printf()`方法,以及`StringBuilder`和`StringBuffer`类。同时,理解并处理GBK这样的特定字符编码对于处理中文字符至关...
### Java字符串格式化String.format()详解 #### 一、引言 `String.format()` 方法是JDK 1.5引入的新特性,它提供了一种灵活且强大的方式来格式化字符串。这种方法类似于C语言中的`printf`函数,允许开发者通过指定...
1. **格式化字符串的基本语法**:在各种编程语言中,如Python的f-string、C++的printf、Java的String.format等,都有各自的字符串格式化方法。理解这些语法对于正确地构造和输出格式化的字符串至关重要。 2. **变量...
"json字符串格式化工具"是针对JSON数据进行美化和整理的工具,主要功能包括将紧凑的JSON字符串转换为易于阅读的格式,添加缩进、换行,以及高亮显示键值对等。这对于开发者调试API接口、查看JSON响应或者理解复杂...
json字符串格式化工具,不用安装,直接运行,美化json字符串,方便,快捷。json字符串格式化工具,不用安装,直接运行,美化json字符串,方便,快捷。json字符串格式化工具,不用安装,直接运行,美化json字符串,...
Java中的字符串格式化功能是处理和展示数据时不可或缺的一部分,尤其在需要将各种数据类型转换为特定格式的字符串时显得尤为重要。本文将深入探讨Java中`String`类的`format()`方法,及其如何用于创建格式化的字符串...
4. **日期和时间字符串格式化** - Java中的`java.util.Date`类和`java.text.SimpleDateFormat`类用于处理日期和时间。`SimpleDateFormat`允许我们自定义日期时间格式,如`"yyyy-MM-dd HH:mm:ss"`。 - 示例代码: ...
#### 二、Java字符串格式化输出 在Java中,`System.out.println()` 是最常用的打印输出语句,但当需要进行复杂的格式化输出时,它就显得力不从心了。此时可以考虑使用 `java.text` 包中的类来实现更为灵活的格式化...
Java 字符串日期数字格式化输出 Java 中的字符串日期数字格式化输出是一种常见的操作,特别是在数据输出和显示时。 Java 提供了多种方式来实现格式化输出,包括使用 NumberFormat、DecimalFormat 和 ...
### Java字符串的编码转换 在Java中,处理不同字符集之间的字符串转换是一项常见任务。尤其是在处理国际化应用时,理解并掌握各种字符编码格式变得尤为重要。下面将介绍几种常见的字符编码格式以及如何在Java中实现...
在Java编程中,验证字符串是否符合JSON(JavaScript Object Notation)格式是一项常见的任务,尤其是在进行前后端数据交互时。JSON是一种轻量级的数据交换格式,它允许数据以键值对的形式存储,易于人阅读和编写,...
JDK1.5中,String类新增了一个很有用的静态方法,这些方法有助于开发人员对字符串的各类操作
在Java编程语言中,字符串...以上只是Java字符串操作的一小部分,实际开发中还有许多其他方法和特性,如国际化(I18N)、正则表达式等,都需要程序员灵活掌握。理解并熟练运用这些操作,能有效提高代码质量和效率。
### Java字符串长度不够前面或后面补0 在Java编程中,有时我们需要确保字符串达到特定的长度,如果实际长度不足,则需要在字符串的前部或后部添加特定字符(如0)来填充,使得最终字符串满足预设长度的要求。本文将...
HiJson工具免去了我们需要联网格式化json字符串的烦恼,无需百度搜索在线格式化,只要安装了JDK,打开就可以用。
在Java编程语言中,字符串是极其重要且常用的数据类型,尤其在Android开发中更是不可或缺。...在实际开发中,还会涉及到更多高级特性和实践技巧,如字符串格式化、正则表达式的复杂使用、字符串的安全问题等。
`SimpleDateFormat`是`java.text`包中的一个子类,它可以用来格式化和解析日期。下面是一个具体的例子: ```java import java.text.SimpleDateFormat; import java.util.Date; public class DateToStringConverter...
在 Java 中,SimpleDateFormat 是一个格式化和解析日期的类。我们可以使用 SimpleDateFormat 将字符串转换为日期,然后比较日期的大小。 首先,我们需要创建一个 SimpleDateFormat 对象,并设置日期格式为 "yyyy-MM...
### Java完美按格式化字符串String转sql.Date 在Java编程中,经常需要处理日期与时间相关的数据。特别是在数据库操作时,经常会遇到需要将字符串类型的日期转换为`java.sql.Date`类型的情况。本文将详细介绍如何...
java代码-使用java解决json字符串格式化的源代码 ——学习参考资料:仅用于个人学习使用!