开始使用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获取年月日时分秒毫秒的更多相关文章

  1. 年月日时分秒毫秒+随机数getSerialNum

    package com.creditharmony.apporveadapter.core.utils; import java.io.ByteArrayInputStream; import jav ...

  2. Sql 中获取年月日时分秒的函数

    getdate():获取系统当前时间 dateadd(datepart,number,date):计算在一个时间的基础上增加一个时间后的新时间值,比如:dateadd(yy,30,getdate()) ...

  3. C语言获取字符年月日时分秒毫秒

    概述 本文演示环境: Windows10 使用C语言获取年月日时分秒毫秒, 代码 #include <iostream> #include <string> #include ...

  4. Asp.net(C#)年月日时分秒毫秒

    年月日时分秒毫秒格式:yyyyMMddHHmmssfff

  5. jquery获取年月日时分秒当前时间

    获取年月日时分秒的当前时间,可按照某种格式显示出来,下面是一种得到如2017年02月02日  00:00:00格式的当前时间 function getCurrentDate(date){ var y ...

  6. 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 ...

  7. JS获取年月日时分秒

    var d = new Date(); ) + "-" + d.getDate() + " " + d.getHours() + ":" + ...

  8. 2018.2.2 java中的Date如何获取 年月日时分秒

    package com.util; import java.text.DateFormat; import java.util.Calendar; import java.util.Date; pub ...

  9. android获取年月日时分秒

    Calendar calendar=Calendar.getInstance(); //获取当前时间,作为图标的名字 String year=calendar.get(Calendar.YEAR)+& ...

随机推荐

  1. 设计模式之Birdge(桥接)模式

    1.出现原因 1.同一个类型,有两个变化的维度(两个维度的抽象:一个抽象部分的抽象,一个实现部分的抽象) 2.如何应对这种“多维度的变化”?如何利用面向对象技术来使得同一类型可以轻松地沿着两个方向变化 ...

  2. Android -- 经验分享

    目录                                                                                             代码中安装 ...

  3. 【收藏】Linux添加/删除用户和用户组

    1.建用户: adduser phpq                             //新建phpq用户 passwd phpq                               ...

  4. Google Guava学习笔记——基础工具类针对Object类的使用

    Guava 提供了一系列针对Object操作的方法. 1. toString方法 为了方便调试重写toString()方法是很有必要的,但写起来比较无聊,不管如何,Objects类提供了toStrin ...

  5. Codeforces Round #353 (Div. 2) E. Trains and Statistic 线段树+dp

    题目链接: http://www.codeforces.com/contest/675/problem/E 题意: 对于第i个站,它与i+1到a[i]的站有路相连,先在求所有站点i到站点j的最短距离之 ...

  6. 如何实现Windows Phone代码与Unity相互通信(插件方式)

    原地址:http://www.cnblogs.com/petto/p/3915943.html 一些废话 原文地址: http://imwper.com/unity/petto/%E5%A6%82%E ...

  7. Sqli-labs less 58

    Less-58 执行sql语句后,并没有返回数据库当中的数据,所以我们这里不能使用union联合注入,这里使用报错注入. Payload:http://127.0.0.1/sqli-labs/Less ...

  8. React Native 简介:用 JavaScript 搭建 iOS 应用(2)

    [编者按]本篇文章的作者是 Joyce Echessa--渥合数位服务创办人,毕业于台湾大学,近年来专注于协助客户进行 App 软体以及网站开发.本篇文章中,作者介绍通过 React Native 框 ...

  9. HDU 1403 Longest Common Substring(后缀数组,最长公共子串)

    hdu题目 poj题目 参考了 罗穗骞的论文<后缀数组——处理字符串的有力工具> 题意:求两个序列的最长公共子串 思路:后缀数组经典题目之一(模版题) //后缀数组sa:将s的n个后缀从小 ...

  10. Nginx状态监控

    通过配置nginx.conf文件来实现对Nginx状态信息的监控. 1.配置nginx.conf vim /usr/local/nginx/conf/nginx.conf 再server块配置项中添加 ...