string time java,【JAVA】之【string转time方法】
第一种:
package org.kodejava.example.util;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
public class StringToTimeExample {
public static void main(String[] args) {
//
// A string of time information
//
String time = "15:30:18";
//
// Create an instance of SimpleDateFormat with the specified
// format.
//
DateFormat sdf = new SimpleDateFormat("hh:mm:ss");
try {
//
// The get the date object from the string just called the
// parse method and pass the time string to it. The method
// throws ParseException if the time string is in an
// invalid format. But remember as we don't pass the date
// information this date object will represent the 1st of
// january 1970.
Date date = sdf.parse(time);
System.out.println("Date and Time: " + date);
} catch (Exception e) {
e.printStackTrace();
}
}
}
第二种:
public staticTime parseHHMM(String time)
{
Time t =newTime();
// if the format is not "HH:MM" we return null
try
{
String hours = time.substring(0,2);
String minutes = time.substring(3);
t.hour = Integer.parseInt(hours);
t.minute = Integer.parseInt(minutes);
}
catch(Exception e)// TODO is this nice enough?
{
return null;
}
returnt;
}
string time java,【JAVA】之【string转time方法】相关推荐
- (备忘)Java数据类型中String、Integer、int相互间的转换
1.Integer转换成int的方法 Integer i; int k = i.intValue(); 即Integer.intValue(); 2.int转换成Integer int i; Inte ...
- JAVA字符串格式化-String.format()的使用
常规类型的格式化 String类的format()方法用于创建格式化的字符串以及连接多个字符串对象.熟悉C语言的同学应该记得C语言的sprintf()方法,两者有类似之处.format()方法有两种重 ...
- Java数据类型中String、Integer、int相互间的转换
1.Integer转换成int的方法 Integer i; int k = i.intValue(); 即Integer.intValue(); 2.int转换成Integer int i; Int ...
- Java中的String,StringBuilder,StringBuffer三者的区别
最近在学习Java的时候,遇到了这样一个问题,就是String,StringBuilder以及StringBuffer这三个类之间有什么区别呢,自己从网上搜索了一些资料,有所了解了之后在这里整理一下, ...
- java中String xx xx_Java 9 紧凑String改进[JEP 254]Java9新特性
在Java 8中,Java中的String由内部表示char[].每个char存储在内存中的2个字节中.oracle的JDK开发人员分析了大量客户端的应用程序堆转储,他们注意到大多数字符串只能使用拉丁 ...
- java中的string函数_java中string.trim()函数的作用实例及源码
trim()的作用:去掉字符串首尾的空格. public static void main(String arg[]){ String a=" hello world "; Str ...
- java诡异的String.split()方法
Reference https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#split(java.lang.String) 正文 ...
- Java中的String字符串
String类是字符串常量类,该类的对象创建后不能修改.要知道:其实String底层就是char数组.而相对而言的StringBuffer/StringBuilder表示的是一个内容可变的字符序列. ...
- java字符_Java String 类
Java String 类 字符串广泛应用 在 Java 编程中,在 Java 中字符串属于对象,Java 提供了 String 类来创建和操作字符串. 创建字符串 创建字符串最简单的方式如下: St ...
- Java系列: JAVA字符串格式化-String.format()的使用(zz)
常规类型的格式化 String类的format()方法用于创建格式化的字符串以及连接多个字符串对象.熟悉C语言的同学应该记得C语言的sprintf()方法,两者有类似之处.format()方法有两种重 ...
最新文章
- 美国DARPA204页可解释人工智能文献综述论文《Explanation in Human-AI Systems》
- python精要(80)-wxpython(2)-helloworld
- HDU - 2795 Billboard(线段树)
- 下载SSH的jar包
- 【elasticsearch】FileAlreadyExistsException:/home/elasticsearch-6.8.0/config/elasticsearch.keysto
- asp.net如何定时执行任务
- ttf字体转换成woff2网页字体快捷方法
- 连接服务器框架协议通信,通信服务协议范本3篇.doc
- SQL Leetcode练习题
- at91sam9260 OpenWRT u-boot移植
- python实现运动模糊图像_OpenCV+Python实现图像运动模糊和高斯模糊!它是编程界的PS!...
- 不敢相信,技术栈,居然被P站秒了
- 5700: 还钱问题
- 顺序表的c语言结构体描述,顺序表的基本方法实现C语言版
- 「苦练基本功」超级大佬推荐工程师必看的书感悟
- java玫瑰花代码_玫瑰花c语言代码
- wor2007添加分节符
- adb连接夜神模拟器提示:adb unable to connect to 127.0.0.162001 cannot connect to 127.0.0.16200 由于目标 计算机积极拒绝
- 图像识别,ocr 技术,有兴趣的可以了解一下
- OOALV的基本实现步骤
热门文章
- Matlab norm 用法小记
- mysql语句修改zencart产品原价为特价的倍数
- web网页版流程图插件-myflow.js-案例demo下载
- [Linux] 安装samba
- 现代成功男人的硬指标:盖房,种树,写书
- 响应式系统的基本原理
- 2020前端面试(一面面试题)
- Spring Cloud构建微服务架构:服务注册与发现(Eureka、Consul)
- BGP——本地优先级选路+BGP路由水平分割机制(讲解+配置命令)
- 阿里云ECS服务器部署HADOOP集群(三):ZooKeeper 完全分布式集群搭建