FormatUtils java格式化 随笔

import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;


public class FormatUtils {


public static Date stringToDate(String str) {
SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");
Date date = null;
try {
date = sdf.parse(str);
} catch (ParseException e) {
e.printStackTrace();
}
return date;
}




/**
     * 将yyyy-MM-dd时间改为yyyy年MM月dd日
     * @param date yyyy-MM-dd格式的时间
     * @return
     */
    public static String getDateWithNYRFormaterByLine(String date){
        String newDateDisplay = date;
        Date newDate = FormatUtils.stringToDate(date);
        if (newDate != null){
        SimpleDateFormat newSimpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日");
        newDateDisplay = newSimpleDateFormat.format(newDate);
        }
        return newDateDisplay;
    }
/**
* 格式化钱
*
* @param num
* @return #,###,##0.00
*/
public static String formatMoney(Double num) {
if (null == num) {
return "0.00";
}
num = Double.valueOf(Math.round(num * 100)) / 100;
DecimalFormat Formatter = new DecimalFormat("#,###,##0.00");
return Formatter.format(num);
}


/**
     * 格式化日期
     */
    public static String formatDateTime(Date date) {
        if (null == date)
            return "";
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        simpleDateFormat.setLenient(false);
        return simpleDateFormat.format(date);
    }
/**
     * 格式化日期
     */
    public static String formatDate(Date date) {
        if (null == date)
            return "";
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        simpleDateFormat.setLenient(false);
        return simpleDateFormat.format(date);
    }


    public static String formatYearMonth(Date date) {
        if (null == date)
            return "";
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");
        simpleDateFormat.setLenient(false);
        return simpleDateFormat.format(date);
    }


    public static String formatYearMonthWithChinese(Date date) {
        if (null == date)
            return "";
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月");
        simpleDateFormat.setLenient(false);
        return simpleDateFormat.format(date);
    }


    public static Date praseStringToDate(String dateString) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
try {
return sdf.parse(dateString);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}


}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Mathcad 是一种功能强大的数学软件,它可以让我们非常方便地进行数学计算和分析。学习使用Mathcad 对我来说是一种挑战,但同时也是一次非常有意义的经历。 首先,通过学习Mathcad,我深刻认识到数学公式和计算的重要性。在过去,我常常依赖计算器和纸笔进行数学计算,但这种方式往往效率不高,并且难以避免出错。而Mathcad 提供了一个直观且可视化的界面,让我们可以更加直观地理解和应用数学原理。 其次,学习Mathcad 也提高了我的数学建模和问题解决能力。在学习过程中,我发现Mathcad 的强大之处在于它能够将数学公式和实际问题相结合。通过输入不同的数学公式和数据,我可以揭示和解决一些实际世界中的问题,例如电路分析、力学运动、概率统计等,这为我提供了宝贵的数学建模实践经验。 此外,通过学习Mathcad,我也掌握了一种全新的数学表达方式。通过使用Mathcad的函数和符号库,我可以更加准确地表达数学概念和计算过程。这种表达方式简洁明了,易于理解和阅读,有助于提高我的数学思维能力和表达能力。 尽管学习Mathcad可能会遇到一些挑战,例如复杂的函数和符号操作,对于初学者来说不太友好,但通过不断实践和学习,我相信我可以克服这些问题,并不断进步。 总的来说,学习Mathcad 是一次充满挑战和收获的过程。它帮助我提高了数学知识和技能,提升了我的数学建模和问题解决能力。我相信在未来的学习和工作中,Mathcad 将成为我强大的数学工具。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值