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

  1. //通过DateFormat获取系统的时间
  2. String currentTime=DateFormat.format("yyyy-MM-dd hh-mm-ss", new Date()).toString();
  3. currentTime="通过DateFormat获取的时间:\n"+currentTime;
  4. //通过SimpleDateFormat获取24小时制时间
  5. SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH-mm-ss", Locale.getDefault());
  6. currentTime+="\n"+"通过SimpleDateFormat获取24小时制时间:\n"+sdf.format(new Date());
  7. //通过SimpleDateFormat获取12小时制时间
  8. sdf=new SimpleDateFormat("yyyy-MM-dd hh-mm-ss", Locale.getDefault());
  9. 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. echo同时输出到多个文件中

    echo "test"| tee -a file1 file2 如果想去掉在屏幕上的显示 echo "test"| tee -a file1 file2 > ...

  2. Nopcommerce 二次开发1 基础

    1  Doamin    酒店 namespace Nop.Core.Domain.Hotels { /// <summary> /// 酒店 /// </summary> p ...

  3. SQLSERVER如何查看索引缺失

    SQLSERVER如何查看索引缺失 当大家发现数据库查询性能很慢的时候,大家都会想到加索引来优化数据库查询性能, 但是面对一个复杂的SQL语句,找到一个优化的索引组合对人脑来讲,真的不是一件很简单的事 ...

  4. IIS发布文件出现:未能加载文件或程序集“xxxx”或它的某一个依赖项。试图加载格式不正确的程序。

    解决方案:IIS——应用程序池—选中网站—高级设置——启用32位应用程序 :true.

  5. shell 中调用其他的脚本

    方法有三种: 1 使用source 2 使用 . 3 使用sh 简单实验: first.sh #!/bin/bashecho 'your are in first file' second.sh #! ...

  6. 批量Clip

    没有建立对应dataset,直接生成featureclass,主要是工作中没几个dataset. # -*- coding: utf-8 -*-__author__ = 'tanshuai' impo ...

  7. js实现图片无缝连接

    效果图 1.首先先看看html和css代码 <style> *{padding:0;margin:0;} #div1{margin:100px auto;background:red;wi ...

  8. 【JAVA】【Eclipse】出现This element neither has attached source nor attached Javadoc...的解决方法

    This element neither has attached source nor attached Javadoc and hence no Javadoc could be found Ec ...

  9. linux dns 配置

    今天线上出现一个bug,图片上传失败. 经过排查发现,上传图片接口调用失败,ping 域名提示 unknow host,ping IP正常. 猜想可能是dns的问题.解决过程如下: /etc 下没有 ...

  10. Processing与Java混编初探

    Processing其实是由Java开发出的轻量级JAVA开发语言,主要用于做原型,有setup.draw两个主接口和几个消息相应接口 Processing和Java混编很简单...在Java中引入外 ...