MessageFormat 类用来格式化消息。非常的好用
import java.util.*;
import java.text.*;
public class MessageFormatDemo {
static void displayMessage(Locale currentLocale) {
System.out.println("currentLocale = " + currentLocale.toString());
System.out.println();
Object[] messageArguments = {
"Mars",
new Integer(7),
new Date()
};
MessageFormat formatter = new MessageFormat("");
formatter.setLocale(currentLocale);
String template = "At {2,time,short} on {2,date,long}, we detected " +
"{1,number,integer} spaceships on the planet {0}.";
formatter.applyPattern(template);
String output = formatter.format(messageArguments);
System.out.println(output);
}
static public void main(String[] args) {
displayMessage(new Locale("en", "US"));
}
}
tempate 参数说明
Arguments for template
|
Argument
|
Description
|
{2,time,short}
|
The time portion of a Dateobject. The short style specifies theDateFormat.SHORT formatting style.
|
{2,date,long}
|
The date portion of a Dateobject. The same Dateobject is used for both the date and time variables. In the Objectarray of arguments the index of the element holding the Date object is 2. (This is described in the next step.)
|
{1,number,integer}
|
A Number object, further qualified with the integernumber style.
|
分享到:
相关推荐
主要介绍了Java中的MessageFormat.format用法实例,本文先是讲解了MessageFormat的语法,然后给出了多个操作实例,需要的朋友可以参考下
消息格式包使用 messageformat.js 编译消息树。 输出中没有全局变量。安装 > npm install messageformat-bundle用法 var messageformatBundle = require ( 'messageformat-bundle' ) ;// Work in progress…应用程序...
Ø java.text.MessageFormat:用于格式化带占位符的字符串。 为了实现程序的国际化,必须先提供程序所需要的资源文件。资源文件的内容是很多key-value对。其中key是程序使用的部分,而value则是程序界面的显示字符...
java中MessageFormat格式化字符串的例子,包括NumberFormat,DateFormat,ChoiceFormat等
主要介绍了Java利用MessageFormat实现短信模板的匹配,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
2. 使用java.text.MessageFormat中的字符串格式,格式为{ 参数序号(从0开始), 格式类形(number | date | time | choice), 格式样式},例如: validation.between=Date must between {0, date, short} and {1, ...
通常来说Android手机没有未接来电的监听器,如果要实现对未接来电的处理,则需要自己编写...import java.text.MessageFormat; import rbase.app.smshelpmate.Config; import rbase.app.smshelpmate.R; import rbase.ap
前端项目-messageformat,multipleformat和selectformat message和i18n工具-一个实现ICU标准的javascript。
一、国际化的相关知识 1、什么是国际化。 程序只有一套,能根据来访者的阅读...5、批量国际化MessageFormat 占位符:aaaa{索引,类型,样式} 索引:0... 类型:date、time、number等 样式: 6、JSTL中的fmt标签
Intl Messageformat Parser 是发送给 AST 的解析消息字符串,它可以格式化一个人的语言环境消息。
1. 介绍.........................................................................................................18 1.1. 关于本书..........................................................................
1. 介绍.........................................................................................................18 1.1. 关于本书...........................................................................
该项目为开发人员提供了有助于使用Crowdin本地化管理平台的工具。 目前,它仅提供java.text.MessageFormat的替代方案,该替代方案不使用单引号作为转义字符。 对于Maven用户:Groupid:com.fathzer工件:jlocal
messageformat.js 的代码镜像模式 此存储库提供用于编辑 MessageFormat 模板字符串的代码镜像模式。 语法高亮代码折叠和 linter 与编辑器集成。 如果您想看到它的实际效果,请尝试。 虽然有很多不同的 ...
代码如下: BrowserExample.java 代码如下:package swt_jface.demo5; import java.text.MessageFormat; import java.util.MissingResourceException; import org.eclipse.swt.SWT; import org.eclipse.swt.SWTError;...
messageformat.net, .NET的ICU MessageFormat实现 用于. NET 的- 更好的用户界面字符串。 这是. NET 中ICU消息格式的实现。 有关该格式的官方信息,请转到: http://userguide.icu-project.org/formatparse/messages...
前端项目-angular-translate-interpolation-messageformat,使用messageformat.js根据某些值插入字符串。
9.6.4 使用MessageFormat处理包含占位符的字符串 349 9.6.5 使用类文件代替资源文件 350 9.6.6 使用NumberFormat格式化数字 350 9.6.7 使用DateFormat格式化日期 352 9.7 本章小结 355 本章练习 355 第10章 ...
ngx-translate编译器,它使用messageformat.js来使用ICU语法编译翻译以处理复数形式和性别 (StackBlitz) 目录 安装 假设您已经安装了 。 使用npm : npm install ngx-translate-messageformat-compiler ...