Java日期类型格式转化

Python021

Java日期类型格式转化,第1张

    public static void main(String[] args) {

        //指定格式

        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")

        //将日期格式化为指定格式的字符串

        String cureDate = format.format(new Date())

        try {

            //将字符串按指定格式转化为日期

            Date date = format.parse(cureDate)

        } catch (ParseException e) {

            e.printStackTrace()

        }

    }

SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy")

SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd")

sdf1.format(sdf.parse(日期))