字符串到日期转换的android [英] String to date conversion android

查看:201
本文介绍了字符串到日期转换的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,我想我的字符串转换为日期数据类型的Andr​​oid应用程序。
我得到通过日期选取器字符串中的格式(2011/12/30)。
我想将其转换成字符串以相同的格式。这是我的code:

I have an android app in which i want to convert my string into date data type. I get the string via date picker in this format ("12/30/2011"). I want to convert it into string in the same format. This is my code:

        Date dateObj = new Date();
        dateFormat = new SimpleDateFormat("MM/dd/yyyy");
        dateFormat.setLenient(false);
        dateObj = dateFormat.parse("12/30/2011");
        Log.v("",""+dateObj);

但我得到这种形式值:

But i get value in this form:

周三12月28日00:00:00 GMT + 05:00 2011

Wed Dec 28 00:00:00 GMT+05:00 2011

推荐答案

帮助?

SimpleDateFormat sdf = new SimpleDateFormat(format);
sdf.format(new Date())

请看看这个

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


public class DateIssue {
    public static void main(String[] args) {
        SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
        System.out.println(sdf.format(new Date()));
    }
}

输出:12/28/2011

在地方

Log.v("",""+dateObj);

使用

 Log.v("",""+sdf.format(new Date()));

你不应该打印原始日期对象,但该格式之一。

这篇关于字符串到日期转换的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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