首页 > 编程语言 > 详细

java格式化

时间:2019-03-22 21:10:26      阅读:162      评论:0      收藏:0      [点我收藏+]

---恢复内容开始---

http://tool.oschina.net/apidocs/apidoc?api=jdk-zh

https://www.jianshu.com/p/c8f16cab35e1#

参考官方的 api说明文档,format是一个抽象接口,已知的实现类有DateFormat,MessageFormat,NumberFormat

关于时间的DateFormat,我们一般是直接使用它的子类:SimpleDateFormat,具体的y,m,d,之类的用法可以参考百度

例子如下:获取当前系统的时间并格式化

package test;

import java.text.SimpleDateFormat;
import java.util.Date;
import org.json.JSONArray;
import org.json.JSONObject;

public class test2 {
    public static void main(String[] args) {

        //获取系统当前时间
        long currentTime = System.currentTimeMillis();
        Date date = new Date(currentTime);
        System.out.println(date);
        //进行格式化,获取自己想要的格式
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日HH时mm分");
        System.out.println(dateFormat.format(date));
        
    }
}

技术分享图片

 

关于NumberFormat,它的直接实现子类有ChoiceFormat和DecimalFormat,我们一般使用DecimalFormat

 

 

---恢复内容结束---

---恢复内容开始---

http://tool.oschina.net/apidocs/apidoc?api=jdk-zh

https://www.jianshu.com/p/c8f16cab35e1#

参考官方的 api说明文档,format是一个抽象接口,已知的实现类有DateFormat,MessageFormat,NumberFormat

关于时间的DateFormat,我们一般是直接使用它的子类:SimpleDateFormat,具体的y,m,d,之类的用法可以参考百度

例子如下:获取当前系统的时间并格式化

package test;

import java.text.SimpleDateFormat;
import java.util.Date;
import org.json.JSONArray;
import org.json.JSONObject;

public class test2 {
    public static void main(String[] args) {

        //获取系统当前时间
        long currentTime = System.currentTimeMillis();
        Date date = new Date(currentTime);
        System.out.println(date);
        //进行格式化,获取自己想要的格式
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日HH时mm分");
        System.out.println(dateFormat.format(date));
        
    }
}

技术分享图片

 

关于NumberFormat,它的直接实现子类有ChoiceFormat和DecimalFormat,我们一般使用DecimalFormat

 

 

---恢复内容结束---

---恢复内容开始---

http://tool.oschina.net/apidocs/apidoc?api=jdk-zh

https://www.jianshu.com/p/c8f16cab35e1#

参考官方的 api说明文档,format是一个抽象接口,已知的实现类有DateFormat,MessageFormat,NumberFormat

关于时间的DateFormat,我们一般是直接使用它的子类:SimpleDateFormat,具体的y,m,d,之类的用法可以参考百度

例子如下:获取当前系统的时间并格式化

package test;

import java.text.SimpleDateFormat;
import java.util.Date;
import org.json.JSONArray;
import org.json.JSONObject;

public class test2 {
    public static void main(String[] args) {

        //获取系统当前时间
        long currentTime = System.currentTimeMillis();
        Date date = new Date(currentTime);
        System.out.println(date);
        //进行格式化,获取自己想要的格式
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日HH时mm分");
        System.out.println(dateFormat.format(date));
        
    }
}

技术分享图片

 

关于NumberFormat,它的直接实现子类有ChoiceFormat和DecimalFormat,我们一般使用DecimalFormat

 

 

---恢复内容结束---

---恢复内容开始---

http://tool.oschina.net/apidocs/apidoc?api=jdk-zh

https://www.jianshu.com/p/c8f16cab35e1#

参考官方的 api说明文档,format是一个抽象接口,已知的实现类有DateFormat,MessageFormat,NumberFormat

关于时间的DateFormat,我们一般是直接使用它的子类:SimpleDateFormat,具体的y,m,d,之类的用法可以参考百度

例子如下:获取当前系统的时间并格式化

package test;

import java.text.SimpleDateFormat;
import java.util.Date;
import org.json.JSONArray;
import org.json.JSONObject;

public class test2 {
    public static void main(String[] args) {

        //获取系统当前时间
        long currentTime = System.currentTimeMillis();
        Date date = new Date(currentTime);
        System.out.println(date);
        //进行格式化,获取自己想要的格式
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日HH时mm分");
        System.out.println(dateFormat.format(date));
        
    }
}

技术分享图片

 

关于NumberFormat,它的直接实现子类有ChoiceFormat和DecimalFormat,我们一般使用DecimalFormat

 

 

---恢复内容结束---

java格式化

原文:https://www.cnblogs.com/zengcongcong/p/10580758.html

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