Android开发之获取系统12/24小时制的时间

//通过DateFormat获取系统的时间
String currentTime=DateFormat.format("yyyy-MM-dd hh-mm-ss", new Date()).toString();
currentTime="通过DateFormat获取的时间:\n"+currentTime;
//通过SimpleDateFormat获取24小时制时间
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH-mm-ss", Locale.getDefault());
currentTime+="\n"+"通过SimpleDateFormat获取24小时制时间:\n"+sdf.format(new Date());
//通过SimpleDateFormat获取12小时制时间
sdf=new SimpleDateFormat("yyyy-MM-dd hh-mm-ss", Locale.getDefault());
currentTime+="\n"+"通过SimpleDateFormat获取12小时制时间:\n"+sdf.format(new Date());

注意: 通过DateFormat方式只能获取12小时制时间

Android获取时间2的更多相关文章

  1. Android获取时间

    java代码: import java.text.SimpleDateFormat;SimpleDateFormat formatter = new SimpleDateFormat ('yyyy年M ...

  2. android 获取时间

    首先,先说下java下可以正常使用的方法: import java.text.DateFormat; import java.text.SimpleDateFormat; import java.ut ...

  3. Android获取系统时间方法的总结

    Android获取系统时间方法的方法有很多种,常用的有Calendar.Date.currentTimeMills等方法. (1)Calendar Calendar获取系统时间首先要用Calendar ...

  4. android中获取时间

    android中获取时间 1)通过calendar类获取 Calendar calendar = Calendar.getInstance();int moth = calendar.get(Cale ...

  5. Android 获取系统时间和网络时间

    有些时候我们的应用中只能使用网络时间,而不能使用系统的时间,这是为了避免用户关闭了使用网络时间的功能后所产生的误差. 直接上代码. 1.清单文件中网络添加权限. <!-- 访问Internet资 ...

  6. Android获取系统时间的多种方法

    Android中获取系统时间有多种方法,可分为Java中Calendar类获取,java.util.date类实现,还有android中Time实现. 现总结如下: 方法一: ? 1 2 3 4 5 ...

  7. Android获取网络时间的方法

    一.通过免费或者收费的API接口获取 1.免费 QQ:http://cgi.im.qq.com/cgi-bin/cgi_svrtime 淘宝:http://api.m.taobao.com/rest/ ...

  8. android 获取Datepicker日期

    1.使用的Android5.0系统,实现上面效果使用了alertdialog 2.布局文件: layout_dataselect <?xml version="1.0" en ...

  9. android开发时间和日期的代码实现工具类(一)

    android开发时间和日期工具类的代码实现: package com.gzcivil.utils; import android.annotation.SuppressLint; import an ...

随机推荐

  1. 在requirejs中使用qunit

    requirejs(['QUnit'], function(qunit) { qunit.test('test name', function(assert) { // 一些测试, assert }) ...

  2. ZeroC Ice 暂记

    摘自: http://weibo.com/p/1001603869896789339575 原文地址: http://www.oschina.net/question/865233_242146 吴治 ...

  3. leetcode 191

    191. Number of 1 Bits Write a function that takes an unsigned integer and returns the number of ’1' ...

  4. Python描述符(descriptor)解密(转)

    原文:http://www.geekfan.net/7862/ Python中包含了许多内建的语言特性,它们使得代码简洁且易于理解.这些特性包括列表/集合/字典推导式,属性(property).以及装 ...

  5. Web前端安全问题

    1.XXS跨站脚本攻击(Cross Site Scripting) 1)通过<script> 举个例子:通过QQ群,或者通过群发垃圾邮件,来让其他人点击这个地址: book.com/sea ...

  6. php:微信公众号token验证失败原因、验证码显示不出来的问题

    ob_clean(); 问题描述: 用微信官方提供的demo验证token是成功的,但是放到自己网站的框架上进行token验证老是提示"token验证失败",经过检查(用生成日志的 ...

  7. Android之sqlite的使用 (转载)

    Android中的SQLite使用 首先创建数据库类 public class DatabaseHelper extends SQLiteOpenHelper {       private stat ...

  8. DevExpress.XtraGrid.GridControl 实现自定义tooltip

    DevExpress.XtraGrid.GridControl 控件默认的tooltip显示的每一个单元格的文本值,但是实际工作中会出现各种需求.我这里就有一个列是折扣率显示的值是0-1之间的两位小数 ...

  9. SRM 146 DIV1 800

    Problem Statement      The purpose of a roundabout is to control the flow of traffic at a busy inter ...

  10. UNIX域套接字(unix domain)

    UNIX域套接字用于在同一台机器上运行的进程之间的通信. UNIX域套接字提供流和数据报两种接口. 说明:UNIX域套接字比因特网套接字效率更高.它仅赋值数据:不进行协议处理,如添加或删除网络报头.计 ...