将Android日期时间转换为MySQL日期时间 [英] Converting android date time into mysql datetime

查看:182
本文介绍了将Android日期时间转换为MySQL日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么办法可以从格式为<MM-DD-YY'的android date和格式为<HH:MM'的时间获取诸如'YYYY-MM-DD HH:MM:SS'之类的日期时间格式存储为mysql中的日期时间格式

Is there any way I can get datetime format like 'YYYY-MM-DD HH:MM:SS' to be stored as datetime format in mysql from android date of format 'MM-DD-YY' and time of format 'HH:MM'

输入: android日期"MM-DD-YY"和android时间"HH:MM"
输出: mysql datetime'YYYY-MM-DD HH:MM:SS'

Input : android date 'MM-DD-YY' and android time 'HH:MM'
Output: mysql datetime 'YYYY-MM-DD HH:MM:SS'

推荐答案

使用 SimpleDateFormat 解析和格式化日期:

Use SimpleDateFormat to parse and format the dates :

// Parse the input date
SimpleDateFormat fmt = new SimpleDateFormat("MM-dd-yyyy HH:mm");
Date inputDate = fmt.parse("10-22-2011 01:00");

// Create the MySQL datetime string
fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = fmt.format(inputDate);

这篇关于将Android日期时间转换为MySQL日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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