简体   繁体   English

如何将日期转换为android中的年数和月数

[英]how to convert date to number of year in android and number of month

I want to get which day of year is it. 我想知道一年的哪一天。 a year have 365 days . 一年有365天。 I want to get which day base on the data , i have . 我想根据数据得到哪一天。 for example : my date is : 2017/01/03 ---> base on this data I found that it means day 2. 例如:我的日期是:2017/01/03 --->基于此数据,我发现这意味着第二天。

You can use Calendar class to get your desired output: 您可以使用Calendar类获得所需的输出:

Calendar cal = Calendar.getInstance(); // get calendar object instance
cal.setTime("set your time here"); // set your desired time here, it can be as Date object, if you've millis then use setTimeInMillis();
cal.get(Calendar.DAY_OF_YEAR); // get day of year like this

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android Date Picker月份为数字 - Android Date Picker month as number 将日期转换为年和月 - Convert Date to Year and Month 如何将字符串月份和年份转换为完整日期? - How to convert string month and year into complete date? 在 Android 中获取年、月和日期 - Getting Year, Month and Date in Android 如何在Android中将“年-月-日”日期格式(例如:2015-05-12-这是从服务器检索到的值)转换为“日-月-年”格式 - How to convert “year-month-day” date format(eg: 2015-05-12-which is a value retrieved from server) to “day-month-year” format in android 如何在我的号码选择器索引中设置当前月和年? - How to set Current Month and year in my number picker index? 如何从当前月份和年份的日期选择器显示以限制显示上一年和月份的android? - How to display from current month and year in date picker to restrict showing previous year and month android? 如何显示仅具有月份和年份字段的Android日期选择器? - How to display date picker for android with only month and year fields? 如何在Android中找到当前日期和时间的周、月和年范围 - How to find the range of week, month and year for current Date and Time in Android Android:月份日期年份的日期格式 - Android: Date Format in Month date year
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM