获得Android的格式化的日期和时间 [英] get formatted date and time in android

查看:290
本文介绍了获得Android的格式化的日期和时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个函数来计算的日期和时间。

I have two function to calculate date and time.

  public static String getFormattedDate(String time) {
    long timeUnix = Long.parseLong(time);
    Date myDate = new Date(timeUnix * 1000);
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MMM d yy");
    return simpleDateFormat.format(myDate);
}

  public static String getFormattedTime(String time) {
    long timeUnix = Long.parseLong(time);
    Date myDate = new Date(timeUnix * 1000);
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("hh:mm:ss");
    return simpleDateFormat.format(myDate);
}

我从他们那里得到输出正确的,我需要的。

I get the correct output from them which I need.

Jul 12 11(date function) and 12:09:45(time function)

我如何计算从该天,如何设置AM / PM与此有关。

How can I calculate days from this and how to set am/pm with this.

我想设置的时间与AM / PM如果是今天的日期,如果是年纪比显示日(周一,周二,周三等),如果它比一周比秀老更MMM d日YY

I am trying to set time with am/pm if it is today's date and if it is older than show the day(mon,tue,wed etc.) and if it is more than week old than show "MMM d yy".

推荐答案

有关AM / PM符号:

For am/pm notation:

SimpleDateFormat dateFormat = new SimpleDateFormat("KK:mm:ss a");
return dateFormat.format(myDate);

KK是的在凌晨小时/时(0-11)的,而HH是的中,日,小时(0-23)

这篇关于获得Android的格式化的日期和时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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