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

考慮 AM/PM 計算 Java 中的日期/時間差

Calculate Date/Time Difference in Java considering AM/PM(考慮 AM/PM 計算 Java 中的日期/時間差)
本文介紹了考慮 AM/PM 計算 Java 中的日期/時間差的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我想使用 Date 和 Calendar 類計算 java 中兩個日期/時間之間的差異.我的格式是2012-01-24 12:30:00 PM".

I want to calculate the difference between two date/time in java using Date and Calendar classes. The format that I have is "2012-01-24 12:30:00 PM".

我已經實現了我自己的方法,并在谷歌上搜索它以與其他人一起工作,但沒有得到正確的提示來處理 AM 和 PM 值.

I have implemented my own method and also google it to work with others, but haven't getting the right hint to handle AM and PM values.

只要時間中有 12(AM/PM),日期/時間差異就會受到影響.例如,如果我的日期/時間為2012-01-24 12:30:00 PM"和2012-01-24 02:30:00 PM",則顯示時差為 10 小時.

The date/time difference got troubled whenever the time have 12(AM/PM) in it. For example if I have date/time "2012-01-24 12:30:00 PM" and "2012-01-24 02:30:00 PM" it shows the difference is 10 hours.

考慮 此鏈接上的代碼 如何修改它來處理 AM 和 PM.

Considering the code on this link how can it be modified to handle AM and PM.

要將字符串日期轉換為日期,我使用以下代碼:

To convert String date into Date I use following code:

    String sessionTimeStart = "2012-01-24 12:30:00 PM";
    String sessionTimerEndOrCurrent = "2012-01-24 02:30:00 PM";
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss a"); 

    Date d1 = null;
    Date d0 = null; 
    try {
        d1 = format.parse(sessionTimeStart);
        d0 = format.parse(sessionTimerEndOrCurrent);
    } catch (ParseException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

推薦答案

問題是你的日期格式:而不是 yyyy-MM-dd HH:mm:ss a 使用 yyyy-MM-dd hh:mm:ss a.

The problem is your date format: instead of yyyy-MM-dd HH:mm:ss a use yyyy-MM-dd hh:mm:ss a.

HH 將是一天中的小時 (0-23),而 hh 將是 AM/PM (1-12) 中的小時.因此,您的日期格式 02:30:00 將被解析為那樣,而不是被轉換為 PM 版本(一天中的小時為 14:30:00).

HH will be the hour in day (0-23) whereas hh will be the hour in AM/PM (1-12). Thus with your date format 02:30:00 will be parsed as just that instead of being converted to the PM version (which in hour of day would be 14:30:00).

這篇關于考慮 AM/PM 計算 Java 中的日期/時間差的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期時間,就像在 UTC 中一樣)
How to convert Gregorian string to Gregorian Calendar?(如何將公歷字符串轉換為公歷?)
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 日之前日期的日歷到日期轉換.公歷到儒略歷切換)
java Calendar setFirstDayOfWeek not working(java日歷setFirstDayOfWeek不起作用)
Java: getting current Day of the Week value(Java:獲取當前星期幾的值)
主站蜘蛛池模板: 欧美啪啪 | 日韩精品免费在线 | 亚洲精品久久久久中文字幕欢迎你 | 亚洲视频免费在线 | 人人玩人人添人人澡欧美 | 综合网在线 | 久久99精品久久 | 色综合九九| 精品伊人久久 | 久久中文字幕电影 | 亚洲成人三区 | 中文字幕综合在线 | 国户精品久久久久久久久久久不卡 | 久久综合888| 国产视频第一页 | 美女久久久久 | 91高清在线观看 | 九一视频在线播放 | 日韩精品色网 | aaaaaaa片毛片免费观看 | www.日韩 | 国产高清美女一级a毛片久久w | 中文字幕高清av | 99在线免费观看视频 | 一级黄色片一级黄色片 | 国产在线一区观看 | 亚洲综合色视频在线观看 | 欧美a区 | 午夜码电影 | 一区二区三区四区av | 国产黄色大片网站 | 在线免费毛片 | 毛片免费视频 | 国产成人综合一区二区三区 | 亚洲精品成人av久久 | 国产免费xxx | 国产又爽又黄的视频 | 日韩午夜 | 亚洲欧洲成人 | 欧美一级免费看 | 久久国产精品91 |