首页 > 其他 > 详细

5.8 日期字符串数字的格式化

时间:2018-05-08 15:41:42      阅读:179      评论:0      收藏:0      [点我收藏+]

数字的格式化

①Math类:  

                abs();    绝对值             

public class Test {

	public static void main(String[] args) {
                 int a = Math.abs(-7);
                System.out.println(a);    // 打印7
}  

                  ceil();    向上取整                    

        floor();   向下取整

public class Test {

	public static void main(String[] args) {
				
		double d1 = Math.ceil(12.345);                                  
		double d2 = Math.ceil(12.745);
		double d3 = Math.floor(12.345);
		double d4 = Math.floor(12.745);
		System.out.println(d1);                          //打印13
		System.out.println(d2);                         //打印13
		System.out.println(d3);                         //打印12
		System.out.println(d4);                         //打印12
         }
}  

                  round();        四舍五入取整

public class Test {

	public static void main(String[] args) {
		
		double d5 = Math.round(13.111);
		double d6 = Math.round(13.711);
		System.out.println(d5);                    //打印13       
		System.out.println(d6);                   //打印14
              }
} 

                  random();     取随机数(0-1,不包括1)

                  还可以用java.util.Random

                                   nextInt(int  bounds)

          全球唯一标识   UUID   一般用于文件上传,重名的。上传时随机生成改名

import java.util.UUID;
public class Test {

	public static void main(String[] args) {
			
		UUID uuid = UUID.randomUUID();
		System.out.println(uuid);               //打印一个很长的名字
        }
}

           Date    时间戳  某一个时间点到当前时间的毫秒数,弊端:服务器快会重名

public class Test {

	public static void main(String[] args) {
			
		Date date = new Date();
		System.out.println(date.getTime());     //一串数字
	}

}

  

       

5.8 日期字符串数字的格式化

原文:https://www.cnblogs.com/syx1997/p/9008369.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!