String format 格式化字符串
来源:互联网 发布:新网域名管理权变更 编辑:程序博客网 时间:2024/04/29 13:17
<pre name="code" class="java">package format;import java.util.Date;import java.util.Locale;public class test {public static void main(String[] args) {String str = null;str = String.format("HI,%s, %s", "hu","hu", "hu");System.out.println(str);/* * HI,hu, hu */System.out.printf("字符型:%c %n", 'A');System.out.printf("布尔型: %b %n", 3 > 7);System.out.printf("整数型(十进制)%d %n", 100 / 2);System.out.printf("整数型(十六进制)0x%x %n", 100);System.out.printf("整数型(八进制)0%o %n", 100);/* * 字符型:A * 布尔型: false * 整数型(十进制)50 * 整数型(十六进制)0x64 * 整数型(八进制)0144 */System.out.printf("格式参数$的使用:%1$d, %2$s %n", 99, "abc");System.out.printf("显示正数的符号: %+d与%d %n", 99, -99);System.out.printf("补0的使用 : %03d %n", 7);System.out.printf("空格的使用: % 8d %n", 7);System.out.printf(".的使用:%,d %n", 9989997);System.out.printf("空格和小数点后面个数:%05.5f %n", 49.8);/* * 格式参数$的使用:99, abc * 显示正数的符号: +99与-99 * 补0的使用 : 007 * 空格的使用: 7 * .的使用:9,989,997 * 空格和小数点后面个数:49.80000 * */Date date = new Date();System.out.printf("显示全部日期和时间信息:%tc %n", date);System.out.printf("年-月-日 格式:%tF %n", date);System.out.printf("月/日/年 格式:%tD %n", date);System.out.printf("HH:MM:SS PM 格式(12时制):%tr %n", date);System.out.printf("HH:MM:SS 格式(24时制):%tT%n", date);System.out.printf("HH:MM 格式(24时制):%tR %n", date);/* * 显示全部日期和时间信息:星期二 九月 09 10:15:42 CST 2014 * 年-月-日 格式:2014-09-09 * 月/日/年 格式:09/09/14 * HH:MM:SS PM 格式(12时制):10:15:42 上午 * HH:MM:SS 格式(24时制):10:15:42 * HH:MM 格式(24时制):10:15 * *//*b的使用,月份简称*/System.out.printf(Locale.US, "英文月份简称:%tb %n", date);System.out.printf("本地月份简称:%tb %n", date);/* * 英文月份简称:Sep * 本地月份简称:九月 *//*B的使用,月份全称*/System.out.printf(Locale.US, "英文月份全称:%tB %n", date);System.out.printf("本地月份全称:%tB %n", date);/* * 英文月份全称:September * 本地月份全称:九月 *//*a的使用,星期简称*/System.out.printf(Locale.US, "英文星期简称:%ta %n", date);System.out.printf("本地星期简称:%ta %n", date);//System.out.printf("本地星期简称:%tA %n", date); 和a一样/* * 英文星期简称:Tue * 本地星期简称:星期二 * *//*C的使用,年前两位*/System.out.printf("年前的两位数字(不足两位前面补0):%tC %n", date);/* * 年前的两位数字(不足两位前面补0):20 *//*y的使用,年后两位*/System.out.printf("年后两位数学(不足两位前面补0): %ty %n", date);/* * 年后两位数学(不足两位前面补0): 14 *//*j的使用,一年的天数*/System.out.printf("一年中的天数(即年的第几天): %tj %n", date);/* * 一年中的天数(即年的第几天): 252 *//*m的使用,月份*/System.out.printf("两位数字的月份(不足两位前面补0): %tm %n", date);/* * 两位数字的月份(不足两位前面补0): 09 *//*d的使用,日*/System.out.printf("两位数字的日(不足两位前面补0): %td %n", date);/* * 两位数字的日(不足两位前面补0): 09 *//*e的使用,日*/System.out.printf("月份的日(前面不补0): %te %n", date);/* * 月份的日(前面不补0): 9 *//*H的使用*/System.out.printf("2位数字24时制的小时(不足2位前面补0):%tH %n", date);/* * 2位数字24时制的小时(不足2位前面补0):10 *//*I的使用*/System.out.printf("2位数字12时制的小时(不足2位前面补0): %tI %n", date);/* * 2位数字12时制的小时(不足2位前面补0): 10 *//*k的使用*/System.out.printf("2位数字24时制的小时(前面不补0): %tk %n", date);/* * 2位数字24时制的小时(前面不补0): 10 *//*l的使用*/System.out.printf("2位数字24时制的小时(前面不补0): %tl %n", date);/* * 2位数字24时制的小时(前面不补0): 10 *//*M的使用*/System.out.printf("2位数字的分钟(不足2位前面补0):%tM %n", date);/* * 2位数字的分钟(不足2位前面补0):15 *//*S的使用*/System.out.printf("2位数字的秒(不足2位前面补0):%tS %n", date);/* * 2位数字的秒(不足2位前面补0):42 *//*L的使用*/System.out.printf("3位数学的毫秒(不足2位前面补0):%tL %n", date);/* * 3位数学的毫秒(不足2位前面补0):408 *//*N的使用*/System.out.printf("9位数字的毫秒数(不足9位前面补0): %tN %n", date);/* * 9位数字的毫秒数(不足9位前面补0): 408000000 *//*p的使用*/System.out.printf(Locale.US, "小写字母的上午或下午标记(英):%tp %n", date);System.out.printf("小写字母的上午或下午标记(本地):%tp %n", date);/* * 小写字母的上午或下午标记(英):am * 小写字母的上午或下午标记(本地):上午 *//*z的使用*/System.out.printf("相对于GMT的RFC822时区的偏移量:%tz %n", date);/* * 相对于GMT的RFC822时区的偏移量:+0800 *//*Z的使用*/System.out.printf("时区缩写字符串:%tZ %n", date);/* * 时区缩写字符串:CST *//*s的使用*/System.out.printf("1970-1-1 00:00:00 到现在所经过的秒数:%ts %n", date);/* * 1970-1-1 00:00:00 到现在所经过的秒数:1410228942 *//*Q的使用*/System.out.printf("1970-1-1 00:00:00 到现在所经过的毫秒数:%tQ %n", date);/* * 1970-1-1 00:00:00 到现在所经过的毫秒数:1410228942408 */}}
0 0
- String format 格式化字符串
- String.format(格式化字符串)
- String.format() 格式化字符串
- String.format() 格式化字符串
- C# 格式化字符串 String.Format
- String.Format格式化字符串一览
- C# 格式化字符串 String.Format
- C# 格式化字符串 String.Format
- C# 格式化字符串 String.Format
- C# String.Format() 格式化字符串
- String.format字符串格式化方法
- string.Format字符串格式化说明
- C# 格式化字符串 String.Format
- C# 格式化字符串 String.Format
- string.Format字符串格式化说明
- string.Format字符串格式化说明
- string.Format字符串格式化说明
- string.Format字符串格式化说明
- php wrapper实现
- MySQL Key值(PRI, UNI, MUL)的含义
- UILabel字体加粗 IOS
- WebUI自动化测试过程中遇到的问题总结
- 基础3
- String format 格式化字符串
- ic_launcher 小米note 修改无效
- Oracle体系结构详细图解
- PHP下Unix时间戳与日期互转(解决1970年前以及2038年后的问题)
- Aurigma Image Uploader的ActiveX / JAVA图像文件上传控件概述
- 怎么使用侧滑菜单SlidingMenu?
- hadoop hdfs
- 语句和数组
- 线程间通信之消费者模式一notifyAll()