Java如何格式化AM-PM格式的时间?
在JAVA中,如何格式化AM-PM格式的时间?
该示例使用SimpleDateFormat(“HH-mm-ss a”)构造函数和SimpleDateFormat类的sdf.format(date)方法格式化时间。
package com.yiibai;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateTimeAmPm {
public static void main(String[] args) {
Date date = new Date();
String strDateFormat = "HH:mm:ss a";
SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat);
System.out.println(sdf.format(date));
}
}
执行上面示例代码,得到以下结果 -
05:33:06 上午
Java如何格式化AM-PM格式的时间?的更多相关文章
- Java如何格式化24小时格式的时间?
在Java中,如何格式化24小时格式的时间?? 此示例使用SimpleDateFormat类的sdf.format(date)方法将时间格式化为24小时格式(00:00-24:00). package ...
- java中如何按一定的格式输出时间, 必须给出例子
题目2: 按一定的格式输出时间 import java.util.*;import java.text.SimpleDateFormat;public class Test { public s ...
- Java-Runoob-高级教程-实例-时间处理:01. Java 实例 - 格式化时间(SimpleDateFormat)
ylbtech-Java-Runoob-高级教程-实例-时间处理:01. Java 实例 - 格式化时间(SimpleDateFormat) 1.返回顶部 1. Java 实例 - 格式化时间(Sim ...
- Java如何以不同国家的格式显示时间?
在Java中,如何以不同国家的格式显示时间? 以下示例使用Locale类和DateFormat类来显示不同国家格式的日期. package com.yiibai; import java.text.D ...
- Java 字符串格式化详解
Java 字符串格式化详解 版权声明:本文为博主原创文章,未经博主允许不得转载. 微博:厉圣杰 文中如有纰漏,欢迎大家留言指出. 在 Java 的 String 类中,可以使用 format() 方法 ...
- Java系列: JAVA字符串格式化-String.format()的使用(zz)
常规类型的格式化 String类的format()方法用于创建格式化的字符串以及连接多个字符串对象.熟悉C语言的同学应该记得C语言的sprintf()方法,两者有类似之处.format()方法有两种重 ...
- JAVA字符串格式化String.format()的使用
JAVA字符串格式化-String.format()的使用常规类型的格式化 String类的format()方法用于创建格式化的字符串以及连接多个字符串对象.熟悉C语言的同学应该记得C语言的sprin ...
- java字符串格式化
转自:JAVA字符串格式化-String.format()的使用(转) 常规类型的格式化 String类的format()方法用于创建格式化的字符串以及连接多个字符串对象.熟悉C语言的同学应该记得C语 ...
- Java字符串格式化记录
最近打log的时候用到了字符串的格式化. Java中String格式化和C语言的很类似.把情况都列出来,以后好查询. public static void main(String[] args) { ...
随机推荐
- Multi-cloud Kubernetes with Triton
https://www.joyent.com/blog/triton-kubernetes-multicloud While running an experimental Kubernetes cl ...
- 每日英语:Bosses May Use Social Media to Discriminate Against Job Seekers
Many companies regularly look up job applicants online as part of the hiring process. A new study su ...
- iOS开发transform的使用
// // ViewController.m // 18-transform的使用 #import "ViewController.h" @interface ViewCont ...
- 【设计模式】适配器模式与Reader、InputStream之间的适配
简述 适配器模式,目的是将A对象通过适配.转换的方式转换成B对象来使用,为什么转换为B对象?因为用户通过依赖B对象来使用. 适配器的实现有两种方式. 继承实现 组合实现 基于Java单继承的机制,组合 ...
- CSAPP 读书笔记 - 2.31练习题
根据等式(2-14) 假如w = 4 数值范围在-8 ~ 7之间 2^w = 16 x = 5, y = 4的情况下面 x + y = 9 >=2 ^(w-1) 属于第一种情况 sum = x ...
- hive的row_number()函数
hive的row_number()函数 功能 用于分组,比方说依照uuid分组 组内可以依照某个属性排序,比方说依照uuid分组,组内按照imei排序 语法为row_number() over (pa ...
- Python实现堆数据结构
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2018/3/18 19:47 # @Author : baoshan # @Site ...
- Huawei AP3030DN固件升级
进入uboot: 上电,当出现Press f of F stop Auto-Boot in 3 seconds: 0 时按键盘上的F键 Password for uboot cmd line : 密码 ...
- LeetCode: Construct Binary Tree from Preorder and Inorder Traversal 解题报告
Construct Binary Tree from Preorder and Inorder Traversal Given preorder and inorder traversal of a ...
- Android Studio SVN使用
昨天弄了一天的Android Studio svn,感觉没有eclipse的svn好装,中间遇到很多的麻烦问题.这里来记录下吧 上传比较简单,就直接贴我看我别的的上传教程. https://blog. ...