码迷,mamicode.com
首页 > 其他好文 > 详细

日期数字格式转化

时间:2018-07-25 22:05:34      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:http   print   limits   .text   pack   text   []   port   each   

package com.gxnu.study.dateformat;

import java.math.BigInteger;
import java.math.RoundingMode;
import java.text.ChoiceFormat;
import java.text.DateFormat;
import java.text.MessageFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.ResourceBundle;

import org.junit.Test;

public class DateFormatEx {
@Test
public void testDateFormat(){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
Date date = new Date();
String str = sdf.format(date);
System.out.println(str);

DateFormat df = DateFormat.getDateInstance(DateFormat.LONG,new Locale("fr","FR"));
System.out.println(df.format(date));
}

@Test
public void testL(){
System.getenv().forEach(((k,v)->System.out.println(k+"\t"+v)));
System.out.println("4656");
System.getProperties().forEach(((k,v)->System.out.println(k+"\t"+v)));
System.out.println("a");
}

@Test
public void testLocalDate(){
LocalDateTime ldt = LocalDateTime.of(2018, 7,25,10,50);
DateTimeFormatter dtf = DateTimeFormatter.ISO_DATE_TIME;
System.out.println(dtf.format(ldt));
Calendar calendar = new GregorianCalendar(2018, 7, 25);
System.out.println(calendar.getTime());
}

@Test
public void testNumberFormat(){
NumberFormat mf = NumberFormat.getPercentInstance(new Locale("ar","AR"));
mf.setRoundingMode(RoundingMode.FLOOR);
System.out.println(mf.format(123456.498));
mf.setRoundingMode(RoundingMode.HALF_UP);
System.out.println(mf.format(123456.498));
}

@Test
public void testResourceBundle(){
ResourceBundle rb = ResourceBundle.getBundle("h",new Locale("en","us"));
String str = rb.getString("name");
System.out.println(str);
}

@Test
public void testNumber(){
BigInteger bi = new BigInteger("5485");
BigInteger bi2 = new BigInteger("5655");
BigInteger gcd = bi.gcd(bi2);
System.out.println(gcd);
System.out.println(new BigInteger("10000000000001"));

}

@Test
public void testMessageFormat(){
int planet=7;
String even = ResourceBundle.getBundle("h",new Locale("en","US")).getString("name");

String result = MessageFormat.format("At {1,time} on {1,date},there are {2} on planet {0,number,currency},", planet,new Date(),even);
System.out.println(result);
}

@Test
public void testChoice(){
MessageFormat form = new MessageFormat("The disk \"{1}\" contains {0}.");
double[] filelimits = {1,2,4,7};
String[] filepart = {"no files","one file","four file","{0,number} files"};
ChoiceFormat fileform = new ChoiceFormat(filelimits,filepart);
form.setFormatByArgumentIndex(0, fileform);

int fileCount = 6;
String diskName = "MyDisk";
Object[] testArgs = {new Long(fileCount),diskName};

System.out.println(form.format(testArgs));
}
}

 

属性文件

技术分享图片

 

日期数字格式转化

标签:http   print   limits   .text   pack   text   []   port   each   

原文地址:https://www.cnblogs.com/jiminluo/p/9368332.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!