如何将日期dd / mm / yyyy转换为yyyy-MM-dd HH:mm:ss Android [英] how to convert a date dd / mm / yyyy to yyyy-MM-dd HH:mm:ss Android

查看:311
本文介绍了如何将日期dd / mm / yyyy转换为yyyy-MM-dd HH:mm:ss Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将dd / mm / yyyy中的日期转换为支持sqlite的格式yyyy-MM-dd'T'HH:mm:ss

How can I convert a date in dd / mm / yyyy to a format that supports sqlite yyyy-MM-dd'T'HH: mm: ss

for示例:

public static String convertStringToData(String stringData)
        throws ParseException {

    SimpleDateFormat sdf = new SimpleDateFormat("dd/mm/aaaa");//yyyy-MM-dd'T'HH:mm:ss
    SimpleDateFormat output = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date data = sdf.parse(stringData);
    String formattedTime = output.format(data);
    return formattedTime;
}


推荐答案

public static String formatDate (String date, String initDateFormat, String endDateFormat) throws ParseException {

    Date initDate = new SimpleDateFormat(initDateFormat).parse(date);
    SimpleDateFormat formatter = new SimpleDateFormat(endDateFormat);
    String parsedDate = formatter.format(initDate);

    return parsedDate;
}

这会将解析后的日期作为字符串返回,格式为(均为初始值)并结束)作为方法的参数。

This will return the parsed date as a String, with the format (both initial and end) as parameters to the method.

这篇关于如何将日期dd / mm / yyyy转换为yyyy-MM-dd HH:mm:ss Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆