java 预定义_Java 使用预定义的日期格式

import java.text.DateFormat;

import java.util.Date;

import java.util.Locale;

/**

from

* 时代Java公众号

**/

public class Main {

public static void main(String[] args) {

// Get the current date

Date today = new Date();

// Print date in the default locale format

Locale defaultLocale = Locale.getDefault();

printLocaleDetails(defaultLocale);

printDate(defaultLocale, today);

// Print date in French format

printLocaleDetails(Locale.FRANCE);

printDate(Locale.FRANCE, today);/** 来 自 N o w J a v a . c o m**/

// Print date in German format. We could also use Locale.GERMANY

// instead of new Locale ("de", "DE").

Locale germanLocale = new Locale("de", "DE");

printLocaleDetails(germanLocale);

printDate(germanLocale, today);

}

public static void printLocaleDetails(Locale locale) {

String languageCode = locale.getLanguage();

String languageName = locale.getDisplayLanguage();

String countryCode = locale.getCountry();

String countryName = locale.getDisplayCountry();

// Print the locale info

System.out.println("Language: " + languageName + "(" + languageCode + "); "

+ "Country: " + countryName + "(" + countryCode + ")");

}

public static void printDate(Locale locale, Date date) {

DateFormat formatter;

String formattedDate;

// Format and print the date in SHORT style

formatter = DateFormat.getDateInstance(DateFormat.SHORT, locale);

formattedDate = formatter.format(date);

System.out.println("SHORT: " + formattedDate);

/**代码未完, 请加载全部代码(NowJava.com).**/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值