久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何使用 SimpleDateFormat.parse() 將 Calendar.toString()

How can I Convert Calendar.toString() into date using SimpleDateFormat.parse()?(如何使用 SimpleDateFormat.parse() 將 Calendar.toString() 轉(zhuǎn)換為日期?)
本文介紹了如何使用 SimpleDateFormat.parse() 將 Calendar.toString() 轉(zhuǎn)換為日期?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我正在開發(fā)一個使用數(shù)據(jù)庫的 Android 應用程序,每次用戶插入新的寄存器時,當前數(shù)據(jù)和時間都會保存在數(shù)據(jù)庫中

I'm developing an Android app that uses a database, every time that the user insert a new register the current data and time is save in the db using

Calendar cal = Calendar.getInstance();

所以,當我從數(shù)據(jù)庫中檢索數(shù)據(jù)時,得到一個這樣的字符串:

So, When I retrieve the data from the db, got a String like this:

java.util.GregorianCalendar[time=1496007575129,areFieldsSet=true,lenient=true,zone=America/Mexico_City,firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2017,MONTH=4,WEEK_OF_YEAR=22,WEEK_OF_MONTH=5,DAY_OF_MONTH=28,DAY_OF_YEAR=148,DAY_OF_WEEK=1,DAY_OF_WEEK_IN_MONTH=4,AM_PM=1,HOUR=4,HOUR_OF_DAY=16,MINUTE=39,SECOND=35,MILLISECOND=129,ZONE_OFFSET=-21600000,DST_OFFSET=3600000]

java.util.GregorianCalendar[time=1496007575129,areFieldsSet=true,lenient=true,zone=America/Mexico_City,firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2017,MONTH=4,WEEK_OF_YEAR=22,WEEK_OF_MONTH=5,DAY_OF_MONTH=28,DAY_OF_YEAR=148,DAY_OF_WEEK=1,DAY_OF_WEEK_IN_MONTH=4,AM_PM=1,HOUR=4,HOUR_OF_DAY=16,MINUTE=39,SECOND=35,MILLISECOND=129,ZONE_OFFSET=-21600000,DST_OFFSET=3600000]

當我嘗試使用 SimpleDateFormat.parse 轉(zhuǎn)換該字符串以在 RecyclerView 中顯示它時,問題出現(xiàn)了,我總是得到相同的日期:09/04/2017.

The problem comes when I try convert that String using SimpleDateFormat.parse to display it in a RecyclerView, I get always the same date: 09/04/2017.

這是我的 RecViewAdapter.java 中的代碼:

This is the code in my RecViewAdapter.java:

@Override
public void onBindViewHolder(ViewHolder holder,int position){
    items.moveToPosition(position);

    String s,d,p,f;


    s = items.getString(ConsultaTomas.SISTOLICA);
    holder.systolica.setText(s);

    d = items.getString(ConsultaTomas.DIASTOLICA);
    holder.diastolica.setText(d);

    p = items.getString(ConsultaTomas.PULSO);
    holder.pulso.setText(p);

    f = items.getString(ConsultaTomas.FECHA);
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");

    try {
        holder.fecha.setText(sdf.format(sdf.parse(f)));

    }catch (ParseException e){
        Log.d("PARSINGFECHA","Error al parcear fecha");
    }


}

其他數(shù)據(jù)在 RecView 中正確顯示并且日歷字符串都不同,因此這些字符串中的日期/小時不一樣.所以,問題是:

The other data is showed correctly in the RecView and the Calendar String are all diferent, so there is not the same date/hour in these strings. So, the question is:

如何使用 SimpleDateFormat.parse()Calendar.toString() 轉(zhuǎn)換為日期?

How can I Convert Calendar.toString() into date using SimpleDateFormat.parse()?

這是在真實設備上運行應用程序的結(jié)果:2個提線木偶"

This is the result running the app in a real device:

推薦答案

需要修改Calendar的存儲方式,調(diào)用getTime(),格式化為想要開始.例如,

You need to modify the way you store the Calendar, call getTime() and format it as desired to begin with. For example,

Calendar cal = Calendar.getInstance();
DateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
System.out.println(sdf.format(cal.getTime()));

這篇關于如何使用 SimpleDateFormat.parse() 將 Calendar.toString() 轉(zhuǎn)換為日期?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關文檔推薦

Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期時間,就像在 UTC 中一樣)
How to convert Gregorian string to Gregorian Calendar?(如何將公歷字符串轉(zhuǎn)換為公歷?)
Java: What/where are the maximum and minimum values of a GregorianCalendar?(Java:GregorianCalendar 的最大值和最小值是什么/在哪里?)
Calendar to Date conversion for dates before 15 Oct 1582. Gregorian to Julian calendar switch(1582 年 10 月 15 日之前日期的日歷到日期轉(zhuǎn)換.公歷到儒略歷切換)
java Calendar setFirstDayOfWeek not working(java日歷setFirstDayOfWeek不起作用)
Java: getting current Day of the Week value(Java:獲取當前星期幾的值)
主站蜘蛛池模板: 亚洲精品视频免费观看 | www.狠狠干 | 天天搞天天搞 | 国产成人在线观看免费 | 亚洲欧美在线视频 | 久久久久一区二区三区 | 91观看| 亚洲精品一区二区另类图片 | 久久精品视频在线免费观看 | 在线一区视频 | 91电影 | 久久久精品| 男人天堂手机在线视频 | 天天精品综合 | 精品av | 久久综合久久综合久久综合 | 国产精品亚洲综合 | www.天天操.com | 国产精品极品美女在线观看免费 | 欧美三级在线 | 国产精品一区在线观看 | 九九热免费观看 | 中文字幕 亚洲一区 | 人人干人人干人人干 | 日韩欧美操 | 国产一区二区欧美 | 懂色av一区二区三区在线播放 | 国产一区二区三区在线 | 在线一区视频 | 久久这里有精品 | 国产在线精品免费 | 国产精品污污视频 | 视频一二区 | 色爱综合网 | 日本精品免费 | 国产精品1区 | 小h片免费观看久久久久 | 欧美一级特黄aaa大片在线观看 | 色性av| 久久亚洲国产精品日日av夜夜 | 欧美激情综合五月色丁香小说 |