java 获取主机IP,主机名、货币格式化、日期格式化、消息格式化

package com;


import java.net.InetAddress;
import java.net.UnknownHostException;
import java.text.DateFormat;
import java.text.MessageFormat;
import java.text.NumberFormat;
import java.util.Date;
import java.util.Locale;

/**
 * @description:
 * @author: mabh
 * @create: 2020/8/29 10:58 上午
 **/
public class FileIO {
     
    public static void main(String[] args) {
     

        //3. 获取主机地址
        try {
     
            System.out.println(InetAddress.getLocalHost());
        } catch (UnknownHostException e) {
     
            e.printStackTrace();
        }

        //4. 货币格式化 保留两位,有货币符号,四舍五入
        NumberFormat currencyInstance = NumberFormat.getCurrencyInstance(Locale.CHINA);

        System.out.println(currencyInstance.format(1127612998.7999995));

        //5.
        final String format = DateFormat.getDateInstance(DateFormat.DATE_FIELD, Locale.CHINA)
                .format(new Date());
        System.out.println(format);

        //6. 消息格式化
        System.out.println(MessageFormat.format("{0}", "123"));

    }
}

java 获取主机IP,主机名、货币格式化、日期格式化、消息格式化_第1张图片

你可能感兴趣的:(java)