如何从SimpleDateFormate()在android系统的时间? [英] How to get time from SimpleDateFormate() in android?

查看:531
本文介绍了如何从SimpleDateFormate()在android系统的时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串这样的: -

I have a String this:-

   Tue Oct 30 13:22:58 GMT+05:30 2012;

我要划分时间和放大器;从SimpleDateFormate日期: -

I want to divide time & date from SimpleDateFormate:-

DateFormat f = new SimpleDateFormat("EEE,MM/dd/yyyy hh:mm:ss);
Date d = f.parse(my string);
DateFormat date = new SimpleDateFormat("MM/dd/yyyy");
DateFormat time = new SimpleDateFormat("hh:mm:ss a");
System.out.println("Date: " + date.format(d));
System.out.println("Time: " + time.format(d));

我收到此错误: -

I am getting this Error:-

 java.text.ParseException: Unparseable date: "Tue Oct 30 13:22:58 GMT+05:30 2012"

请告诉我什么问题。
谢谢,
Deepanker

Please Tell me whats the problem. Thanks, Deepanker

推荐答案

您戳字符串不匹配模式:

Your timestamp string does not match your pattern:

Tue Oct 30 13:22:58 GMT+05:30 2012

没办法像(更不用说在SimpleDataFormat初始化行语法错误):

is no way like (not to mention syntax error in the SimpleDataFormat initialization line):

EEE,MM/dd/yyyy hh:mm:ss

所以,你需要做的模式匹配的输入数据。由SimpleDateFormat的支持的所有字段这里描述。

这篇关于如何从SimpleDateFormate()在android系统的时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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