android - 将日期时间转换为 "April 6th, 2012 "格式

标签 android

我想在日期字符串的"6th 7th.. etc."中获取day

我试过了SimpleDateFormater &也试试DateFormatSymbols .我没有收到 String Required。

有什么解决方法吗?

最佳答案

SimpleDateFormat format = new SimpleDateFormat("d");
String date = format.format(new Date());

if(date.endsWith("1") && !date.endsWith("11"))
    format = new SimpleDateFormat("EE MMM d'st', yyyy");
else if(date.endsWith("2") && !date.endsWith("12"))
    format = new SimpleDateFormat("EE MMM d'nd', yyyy");
else if(date.endsWith("3") && !date.endsWith("13"))
    format = new SimpleDateFormat("EE MMM d'rd', yyyy");
else 
    format = new SimpleDateFormat("EE MMM d'th', yyyy");

String yourDate = format.format(new Date());

试试这个, 这看起来像一些静态但工作正常...

关于android - 将日期时间转换为 "April 6th, 2012 "格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10316827/

相关文章:

javascript - 覆盖 Android 后退按钮行为仅适用于 PhoneGap(版本 6.2.0)的第一页

java - 安卓Java : Show the value only of `id` when a listrow is selected

android - 在 android-sdk 目录中找不到示例

android - 在 Android 服务中的 WindowManager 中为 ImageView 设置动画

java - 无法使用相机 Intent 启动 ActivityForResult()

Android:可滚动(位图)屏幕

android - 搜索 Activity 是否返回结果?

android - 如何在一个应用程序中使用多个 ReactNativeHosts 进行 CodePush?

android - 在模拟器 android 上停止 Internet 访问

android - 带有android回收器 View 的 picasso 不加载图像