没有合适的资源?快使用搜索试试~ 我知道了~
首页java中时间格式化输出
资源详情
资源评论
资源推荐

package hello;
import java.text.*;
import java.ul.*;
public class DateFormatTest
{
//显示日期
public void showDate(Date date, int datestyle, Locale locale)
{
DateFormat currentDateFormat =
DateFormat.getDateInstance(datestyle,locale);
//创建 DateFormat 对象 currentDateFormat,用来分析传入参数 locale 的日期格式
String dateString = currentDateFormat.format(date);
System.out.println("The date is: " + dateString);
}
//显示时间
public void showTime(Date date, int mestyle, Locale locale)
{
DateFormat currentTimeFormat =
DateFormat.getTimeInstance(mestyle,locale);
String meString = currentTimeFormat.format(date);
System.out.println("The Time is: " + meString);
}
public stac void main(String[] args)
{
int styles[] = {DateFormat.DEFAULT,
DateFormat.FULL,
DateFormat.LONG,
DateFormat.SHORT};
//获得当前日期和时间
Date date = new Date();
DateFormatTest test = new DateFormatTest();
//打印中国日期和时间
System.out.println("中国:");
test.showDate(date, styles[0], Locale.CHINA);
test.showTime(date, styles[0],Locale.CHINA);
//打印美国日期和时间
System.out.println("美国:");
test.showDate(date, styles[0], Locale.US);
test.showTime(date, styles[0],Locale.US);
}
}


















安全验证
文档复制为VIP权益,开通VIP直接复制

评论0