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

Java:根據(jù)時(shí)區(qū)計(jì)算月末日期

Java: Calculate month end date based on timezone(Java:根據(jù)時(shí)區(qū)計(jì)算月末日期)
本文介紹了Java:根據(jù)時(shí)區(qū)計(jì)算月末日期的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時(shí)送ChatGPT賬號(hào)..

我有方法根據(jù)時(shí)區(qū)查找月末日期.

I have method to find month end date based on the timezone.

Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("CET"));
calendar.set(
    Calendar.DAY_OF_MONTH, 
    calendar.getActualMaximum(Calendar.DAY_OF_MONTH)
);
System.out.println(calendar.getTime());`

它顯示輸出:Thu Aug 30 18:04:54 PDT 2018.

但是,它應(yīng)該給我 CET 的輸出.

It should, however, give me an output in CET.

我錯(cuò)過了什么?

推薦答案

Calendar.getTime() 方法返回一個(gè) Date 對(duì)象,然后將其打印在代碼中.問題是 Date 不包含任何時(shí)區(qū)的概念,即使您使用 Calendar.getInstance() 指定了時(shí)區(qū)稱呼.是的,這確實(shí)令人困惑.

The Calendar.getTime() method returns a Date object, which you then printed in your code. The problem is that the Date class does not contain any notion of a timezone even though you had specified a timezone with the Calendar.getInstance() call. Yes, that is indeed confusing.

因此,為了在特定時(shí)區(qū)打印 Date 對(duì)象,您必須使用 SimpleDateFormat 類,打印前必須調(diào)用 SimpleDateFormat.setTimeZone() 指定時(shí)區(qū).

Thus, in order to print a Date object in a specific timezone, you have to use the SimpleDateFormat class, where you must call SimpleDateFormat.setTimeZone() to specify the timezone before you print.

這是一個(gè)例子:

import java.util.Calendar;
import java.util.TimeZone;
import java.text.SimpleDateFormat;

public class TimeZoneTest {

    public static void main(String argv[]){
        Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("CET"));
        calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
        System.out.println("calendar.getTime(): " + calendar.getTime());

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss z");
        sdf.setTimeZone(TimeZone.getTimeZone("CET"));
        System.out.println("sdf.format(): " + sdf.format(calendar.getTime()));
     }
}

這是我電腦上的輸出:

calendar.getTime(): Fri Aug 31 01:40:17 UTC 2018
sdf.format(): 2018-Aug-31 03:40:17 CEST

這篇關(guān)于Java:根據(jù)時(shí)區(qū)計(jì)算月末日期的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期時(shí)間,就像在 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:獲取當(dāng)前星期幾的值)
主站蜘蛛池模板: 最新高清无码专区 | 欧美中文字幕在线观看 | 国产一级在线 | 亚洲国产精品一区二区三区 | 成人不卡 | 一级毛片在线播放 | 久久亚 | 国产激情网站 | 成人国产精品久久 | 国产一区二区自拍 | 一区二区三区视频在线 | 在线观看中文字幕一区二区 | 黄色片免费看视频 | 国产一区二区免费 | 国产一区二区三区 | 欧美视频免费在线 | 国产中文字幕在线观看 | 国产传媒在线观看 | 久久男人 | 欧美精品一区二区三区在线 | 国产一区二区精 | 免费在线观看av网址 | 日韩国产中文字幕 | 久久成人一区二区三区 | 亚洲精品久久久蜜桃 | 欧美一级淫片免费视频黄 | 日韩精品一区二区三区在线播放 | 久久伊人青青草 | 亚洲一区二区中文字幕 | 午夜免费网站 | 国产露脸对白88av | 久久久国产一区二区三区四区小说 | 国产精品免费一区二区三区 | 国产成人久久精品一区二区三区 | 人人叉 | 人人看人人射 | 日本在线观看视频 | 国产精品一区三区 | 亚洲精品一 | 成年免费视频 | 日韩一区不卡 |