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

Java 日歷總是顯示相同的時間

Java Calendar always shows the same time(Java 日歷總是顯示相同的時間)
本文介紹了Java 日歷總是顯示相同的時間的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

下面是我的代碼.

public class TestCalendar {

public static void main(String[] args){
    int unique_id = Integer.parseInt("" + Calendar.HOUR + Calendar.MINUTE
            + Calendar.SECOND);

    System.out.println(unique_id);
}
}

Calendar.HOUR 應該給我

Calendar.HOUR is supposed to give me

public static final int HOUR 用于獲取和設置的字段編號,指示早上的時間或下午.HOUR 用于 12 小時制 (0 - 11).中午和午夜用 0 表示,而不是到 12 點.例如,在晚上 10:04:15.250,HOUR 是 10.

public static final int HOUR Field number for get and set indicating the hour of the morning or afternoon. HOUR is used for the 12-hour clock (0 - 11). Noon and midnight are represented by 0, not by 12. E.g., at 10:04:15.250 PM the HOUR is 10.

無論我運行多少次代碼,它總是給我相同的 unique_id.(101213),我機器上的當地時間是下午 1:30.我在這里做錯了什么?

It doesnt matter how many times I run this code, it always gives me the same unique_id. (101213) and my local time on my machine is 1:30pm. What am I doing wrong here?

謝謝.

推薦答案

您的代碼只是連接常量,Calendar 定義這些常量以識別其中的一些字段.要獲取這些字段的值,請調用 Calendar.get() 并將常量標識符作為參數傳遞:

Your code is just concatenating constants, that the Calendar defines to identify some of it's fields. To get values of these fields, call Calendar.get() and pass the constant identifier as an argument:

public class TestCalendar {

public static void main(String[] args){
    Calendar c = Calendar.getInstance();
    int unique_id = Integer.parseInt("" + c.get(Calendar.HOUR) + c.get(Calendar.MINUTE)
            + c.get(Calendar.SECOND));

    System.out.println(unique_id);
}
}

上述方法可行,但結果與唯一 ID 相差甚遠.要獲得唯一標識時間點的 ID(精度為毫秒),請考慮 Calendar.getTimeInMillis().

The above would work, but the result will be far from unique ID. To get an ID uniquely identifying a point in time (with the precision of milliseconds), consider Calendar.getTimeInMillis().

這篇關于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:獲取當前星期幾的值)
主站蜘蛛池模板: 亚洲激情欧美 | 中文一级片 | 欧美精品久久久久久久多人混战 | 黑人巨大精品欧美一区二区 | 欧美一区二区在线播放 | 日韩av在线网址 | 久久一区精品 | 福利视频1000 | 黑人系列合集h | 91亚洲国产成人久久精品麻豆 | 日韩黄色一级片 | 黄色网在线 | 免费黄色一级视频 | 黄色在线观看免费 | 亚洲一区免费 | 一区二区三区久久 | 中文字幕在线一区二区三区 | 午夜在线观看视频网站 | 日韩在线一区二区三区 | 国产高清免费 | 欧美国产激情 | av网在线 | 午夜时刻免费入口 | 日本在线天堂 | 精品亚洲一区二区三区 | 一区二区三区视频在线 | 国产三级精品三级在线观看 | 日韩欧美小视频 | 日本三级大片 | 婷婷导航 | av一区二区在线观看 | 国产伦精品一区二区三区视频我 | 性色在线 | 免费在线观看黄 | 欧美一级视频在线观看 | 亚洲午夜18毛片在线看 | 黄色一级大片在线免费看国产一 | 久久久久久久国产精品 | 国产做受视频 | 日韩欧美专区 | 91蜜桃视频 |