久久久久久久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:獲取當前星期幾的值)
主站蜘蛛池模板: 成人免费观看男女羞羞视频 | 91色视频在线观看 | 亚洲成人免费 | 欧美一级黄色片在线观看 | 国产精品亚洲成在人线 | 91精品国产99| 国产免费一区二区三区最新6 | 亚洲欧美视频在线观看 | 精品国产乱码久久久久久88av | 亚洲高清一区二区三区 | 欧美日韩成人一区二区 | 中文字幕一区二区三区不卡在线 | av网站在线免费观看 | 一区二区三区观看视频 | 国产三级 | 波多野结衣一区二区 | 天天射影院 | 91精品在线播放 | 亚洲综合色视频在线观看 | 亚洲高清一区二区三区 | 国产高清在线 | 午夜日韩视频 | 国产高清美女一级a毛片久久w | 亚洲一区二区三区四区视频 | 天天操天天插天天干 | 在线看91| 一区二区三区高清在线观看 | 神马久久久久久久久久 | 亚洲欧美日韩在线 | 国产日韩一区二区三区 | 欧美精品乱码久久久久久按摩 | 日本福利在线 | 人人玩人人添人人澡欧美 | 色中文在线 | 欧美xxxx色视频在线观看免费 | 日韩一区二区三区在线 | 亚洲精品成人在线 | 一区二区三区免费网站 | japan25hdxxxx日本| 中文字幕精品一区二区三区精品 | 成年人视频免费在线观看 |