Android Calendar获取年月日时分秒毫秒
开始使用new Date()测试,并用通过date.getMonth(),和date.getDay()获取,不过后来发现这两个访求是jdk1.1版本的,现在已经不用了,而且结果也不正确.
int month = (date.get(Calendar.MONTH))+;
int day = date.get(Calendar.DAY_OF_MONTH);
获取当前的月份和日期
试了一下,果然正确
后来查看java doc文档,MONTH字段解释如下
Field number for get and set indicating the month. This is a calendar-specific value. The first month of the year is JANUARY which is 0; the last depends on the number of months in a year.
这个字段的值只是说明get()的属性字段值,来获取month的
以下为获取其它:
Calendar CD = Calendar.getInstance();
int YY = CD.get(Calendar.YEAR) ;
int MM = CD.get(Calendar.MONTH)+;
int DD = CD.get(Calendar.DATE);
int HH = CD.get(Calendar.HOUR);
int NN = CD.get(Calendar.MINUTE);
int SS = CD.get(Calendar.SECOND);
int MI = CD.get(Calendar.MILLISECOND); Calendar cal = Calendar.getInstance(); //当前年
int year = cal.get(Calendar.YEAR);
//当前月
int month = (cal.get(Calendar.MONTH))+;
//当前月的第几天:即当前日
int day_of_month = cal.get(Calendar.DAY_OF_MONTH);
//当前时:HOUR_OF_DAY-24小时制;HOUR-12小时制
int hour = cal.get(Calendar.HOUR_OF_DAY);
//当前分
int minute = cal.get(Calendar.MINUTE);
//当前秒
int second = cal.get(Calendar.SECOND);
//0-上午;1-下午
int ampm = cal.get(Calendar.AM_PM);
//当前年的第几周
int week_of_year = cal.get(Calendar.WEEK_OF_YEAR);
//当前月的第几周
int week_of_month = cal.get(Calendar.WEEK_OF_MONTH);
//当前年的第几天
int day_of_year = cal.get(Calendar.DAY_OF_YEAR);
Android Calendar获取年月日时分秒毫秒的更多相关文章
- 年月日时分秒毫秒+随机数getSerialNum
package com.creditharmony.apporveadapter.core.utils; import java.io.ByteArrayInputStream; import jav ...
- Sql 中获取年月日时分秒的函数
getdate():获取系统当前时间 dateadd(datepart,number,date):计算在一个时间的基础上增加一个时间后的新时间值,比如:dateadd(yy,30,getdate()) ...
- C语言获取字符年月日时分秒毫秒
概述 本文演示环境: Windows10 使用C语言获取年月日时分秒毫秒, 代码 #include <iostream> #include <string> #include ...
- Asp.net(C#)年月日时分秒毫秒
年月日时分秒毫秒格式:yyyyMMddHHmmssfff
- jquery获取年月日时分秒当前时间
获取年月日时分秒的当前时间,可按照某种格式显示出来,下面是一种得到如2017年02月02日 00:00:00格式的当前时间 function getCurrentDate(date){ var y ...
- java Date获取 年月日时分秒
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3 ...
- JS获取年月日时分秒
var d = new Date(); ) + "-" + d.getDate() + " " + d.getHours() + ":" + ...
- 2018.2.2 java中的Date如何获取 年月日时分秒
package com.util; import java.text.DateFormat; import java.util.Calendar; import java.util.Date; pub ...
- android获取年月日时分秒
Calendar calendar=Calendar.getInstance(); //获取当前时间,作为图标的名字 String year=calendar.get(Calendar.YEAR)+& ...
随机推荐
- 监听文本框输入开发仿新浪微博限制输入字数的textarea插件
监听文本框输入 Firefox.Chrome.IE9,IE10 均支持 oninput 事件,此外所有版本的 IE 均支持 onpropertychange 事件. oninput 事件在用户输入.退 ...
- preseed.cfg分区设定案例
很久之前做ubuntu的PXE配置ubuntu的preseed费了很大的力气,总结的不多,现在温习一下. 就我所接触的,有分区普通磁盘,LVM,和raid三种方式.其中前两中方式比较多,raid方式是 ...
- Codeforces Round #164 (Div. 2) E. Playlist 贪心+概率dp
题目链接: http://codeforces.com/problemset/problem/268/E E. Playlist time limit per test 1 secondmemory ...
- xp/2003开关3389指令
开启3389: @echo offtitle 开启3389clsrem 开启3389reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\ ...
- Windows Live Writer安装失败错误解决方案
初次使用博客园.看到官方推荐Windows Live Writer来写作博客.看着也不错.可以离线写作.不用担心浏览器突然卡卡卡,未响应的危险. Windows Live Writer是博客园推荐博客 ...
- SQLserver分页查询实例
Sqlserver数据库分页查询一直是Sqlserver的短板,闲来无事,想出几种方法,假设有表ARTICLE,字段ID.YEAR...(其他省略),数据53210条(客户真实数据,量不大),分页查询 ...
- MySQL 操作表命令
新建表: create table Itemcats (id int(11) not null auto_increment, primary key (id)) engine=MyISAM auto ...
- Razor语法学习
原文:http://www.cnblogs.com/youring2/archive/2011/07/24/2115254.html 1.Razor的文件类型 Razor支持两种文件类型,分别是.cs ...
- ASP.NET和JSP相似方法总结(持续中。。)
一.HTTP请求处理 1.获取GET请求数据 ASP.NET:Request.QueryString[name] JSP:request.getParameter(String name); 2.解决 ...
- JQuery原理及深入解析--转载
总体架构 jQuery是个出色的javascript库,最近结合它写javascript,看了下源码. 先从整体.全局的看,jQuery的源码几乎都在下面的代码中: (function() { //… ...