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

按時區轉換日期

Convert Date by TimeZone(按時區轉換日期)
本文介紹了按時區轉換日期的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

在上面的代碼中,我想將服務器的時區 (GMT-02:00) 的日期轉換為我的設備 (GMT-03:00) 的時區.但我總是有相同的服務器日期.我做錯了什么?

In that code above I want to transform a Date by the TimeZone of Server (GMT-02:00) to TimeZone from my Device (GMT-03:00). But I Always have the same Date of the server. What I doing wrong?

時區 timeZoneServer = TimeZone.getTimeZone(timeZoneServerString);長時間 = new Long(Long.valueOf(timeInMilis));

TimeZone timeZoneServer = TimeZone.getTimeZone(timeZoneServerString); Long time = new Long(Long.valueOf(timeInMilis));

        Calendar calendarDateServer =   Calendar.getInstance(timeZoneServer);
        calendarDateServer.setTimeInMillis(time);
        long miliServer = calendarDateServer.getTimeInMillis();

        TimeZone timeZoneMeu = TimeZone.getDefault();
        Calendar meuCalendario =  new GregorianCalendar();
        meuCalendario.setTimeZone(timeZoneMeu);

        meuCalendario.setTimeInMillis(miliServer);  
        Date transformedDate = meuCalendario.getTime();


        return transformedDate; 

推薦答案

我做錯了什么?

您假設 Date 有一個時區作為開始.它沒有.Calendar 可以,但 Date 自 Unix 紀元以來只有 毫秒.它不知道日歷系統或時區.這只是一個時間點.

You're assuming that a Date has a time zone to start with. It doesn't. A Calendar does, but a Date is just milliseconds since the Unix epoch. It doesn't know about calendar systems or time zones. It's just a point in time.

不清楚你想對結果做什么 - 但如果它是格式化顯示的問題,只需使用 SimpleDateFormat 并在 that 上設置時區而是.

It's not clear what you want to do with the result - but if it's a matter of formatting it for display, just use SimpleDateFormat and set the time zone on that instead.

我還強烈建議您使用 Joda Time 而不是內置類型...這是一個更明智的 API.

I would also strongly recommend that you use Joda Time instead of the built-in types... it's a much more sensible API.

這篇關于按時區轉換日期的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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:獲取當前星期幾的值)
主站蜘蛛池模板: 亚洲自拍偷拍av | 男女羞羞视频大全 | 欧美成人a∨高清免费观看 欧美日韩中 | 九九综合 | 国产午夜精品久久久久免费视高清 | 97精品国产97久久久久久免费 | 国内自拍真实伦在线观看 | 日韩欧美在线视频 | 欧美a在线 | 激情福利视频 | 久久久日韩精品一区二区三区 | 欧美精品一区二区三区四区五区 | av在线一区二区三区 | 草久在线 | 欧美一级电影免费 | 亚洲免费在线视频 | 日韩视频精品在线 | 免费成人国产 | 中文成人在线 | 亚洲精品乱码久久久久久9色 | 国产免费一区二区三区最新6 | 日韩欧美在线视频 | 亚洲97 | 久久久久国色av免费观看性色 | 天天综合久久 | 四虎影院新地址 | 国产伦精品一区二区三区四区视频 | 国产乱码精品一区二区三区中文 | 国产欧美精品 | 久久福利 | 天天操天天摸天天干 | 欧美日韩成人 | 羞羞视频免费观 | 国产一区二区三区在线视频 | 国产午夜精品久久久久免费视高清 | 久久亚洲国产精品 | 久久小视频 | 久久久av| 国内精品视频在线 | 日韩欧美精品 | 国产在线精品一区 |