时间格式转换
来源:互联网 发布:数据恢复精灵的注册码 编辑:程序博客网 时间:2024/05/21 17:44
本博客仅为自己开发日记,对此文有任何适的朋友请关闭!
1、项目需求:通过提取数据库文章上传时间,然后转换自己想要的格式
2、开发环境:某RecyclerView的Adapter里,mTextView控件显示数据库得到的时间
3、RecyclerView的Adapter片段代码:
@Override public void onBindViewHolder(SinglePhotoViewAdapter.ViewHolder holder, int position) { holder.mTextView.setText(strDate(newdate(mdate.get(position).getCreatedAt())));
//mdate.get(position).getCreatedAt() 从数据集mdate中获取某一行数据的CreatedAt时间数据 }
4、时间转换代码(string转date或date转string):
public static Date newdate(String time){ Date date = null; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try { date = sdf.parse(time); } catch (ParseException e) { e.printStackTrace(); } return date; }
//上面代码先把数据库的String类型的日期转成Date类型,然后通过下面的代码把Date类型日期转成想要的String类型并显示到TextView上 public static String strDate(Date path) { SimpleDateFormat formatter = new SimpleDateFormat("MM月dd日yyyy年"); //可转换成自己想要的格式,比如:yyyy年MM月dd日,dd日MM月yyyy年等 String newTime = formatter.format(path); return newTime; }
1 0
- .net时间格式转换
- Java时间格式转换
- 时间格式转换
- 时间格式转换问题
- 时间格式转换
- sql时间格式转换
- mysql 时间格式转换
- 关于时间格式转换
- C#时间格式转换
- 数据库时间格式转换
- 时间转换格式操作
- Mysql时间格式转换
- sql 时间格式转换
- 时间格式转换
- 获取时间格式转换
- 时间格式转换
- SQL时间转换格式
- sql 时间格式转换
- pat-a1100. Mars Numbers (20)
- POJ 3429 Geometry with a ruler 可能会
- HDU 2086 A1=? [数学问题]
- 利用css话三角
- BZOJ3437: 小P的牧场
- 时间格式转换
- IntelliJ IDEA 提交代码到 GitHub
- 透视学现象如何产生?
- springMvc Model
- BZOJ4652: [Noi2016]循环之美
- ubuntu centos上安装jdk
- 企业商机舆情系统需要做什么方面
- IDEA激活服务器
- 第一篇博客