如何与给定日期时间功能分开显示日期和时间? [英] How do I display date and time separately from a give datetime function?

查看:150
本文介绍了如何与给定日期时间功能分开显示日期和时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是插入并玩一个示例代码,以获取大量聊天/消息收发应用程序。我正在使用函数gettimedate,以便在我的模型类中具有以下内容:

I am just plugging and playing with a sample code to get a hang of chatting/messaging apps. I am using a function gettimedate such that, in my model class I have the following:

private volatile long mTimedate;

public myclass(....,DateType date,...){
        mTimedate = date != null ? date.time : new Date().getTime();

}
public final long getTimedate() {
        return mTimedate;
    }
public int hashCode() {
        if (mId != null) {
            return mId.hashCode();
        }

        int hash = mBody == null ? 0 : mBody.hashCode();
        return 31 * hash + (new Long(mTimedate)).hashCode();
    }
public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }

        if (!(obj instanceof myclass)) {
            return false;
        }

        myclass other = (myclass) obj;
        return mId != null ? mId.equals(other.mId) : other.mId == null
                && (mBody == null ? other.mBody == null : mBody.equals(other.mBody))
                && mTimedate == other.mdate;
    }

现在,我想知道如何使用此时间日期函数,例如我可以从同一函数gettimedate()中提取 Month -date,year作为我的视图的顶部,作为其底部 12小时制的时间。

Now, I wonder, how do I use this time date function, such that I can extract "Month -date, year " for top of my view and for the bottom part "time in 12 hr format" from the same function gettimedate().

这是我正在使用此功能进行显示的适配器:

Here's my adapter where I am using this function for display:

 holder.txtInfo.setText(String.valueOf(new Date(msg.getTimedate())));

会返回整个程序包,如 Mon Oct 19,13:03:03 EDT 2015
,但我只需要分段使用即可获得不同的视图。提示:如何在2个不同的地方使用它?

which returns the whole package as say "Mon Oct 19 ,13:03:03 EDT 2015" but I only need to use it in pieces for different views. Any clue how I can go about it to use it in 2 different places?

PS:对于粗略的工作代码示例,这是示例代码:
< a href = http://www.codeproject.com/Tips/897826/Designing-Android-Chat-Bubble-Chat-UI rel = nofollow> http://www.codeproject.com/Tips/897826/ Designing-Android-Chat-Bubble-Chat-UI

P.S: For a rough working code sample , here's a sample code: http://www.codeproject.com/Tips/897826/Designing-Android-Chat-Bubble-Chat-UI

此外,我想修改此测试代码以查看是否可以在顶部显示日期每天仅进行一次对话,每次对话的时间格式均为12小时,例如example(4:35 pm),就像在任何标准聊天中一样。反正上面的代码可以做到这一点吗?

Also , i would like to modify this test code to see if I can show the date on top for the day of the conversation only once and the just the 12hr time format for each and every conversation ,example( 4:35pm) , just like in any standard chat. Is there anyway to do that with the above code?

谢谢!

推荐答案

使用它:

Date date = new Date();
SimpleDateFormat tryDateFormat = new SimpleDateFormat("EEEE MMMM-dd-yyyy");
String formattedDate = tryDateFormat.format(date);

System.out.println(formattedDate);

打印此图片

Tuesday October-20-2015

这篇关于如何与给定日期时间功能分开显示日期和时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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