获得Android的格式化的日期和时间

编程入门 行业动态 更新时间:2024-10-15 18:26:26
本文介绍了获得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的格式化的日期和时间

本文发布于:2023-07-07 04:21:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1058714.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:日期   时间   Android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!