前言我们在做项目时候经常需要对字符串进行处理,判断,操作,所以我就总结了一下java 字符串一些常用操作,和推荐比较好用我在自用的工具类,毕竟有轮子我们自己就不用重复去写了,提供开发效率,剩下的时间就去约女朋友吧哈哈哈!!!!java 内置操作format我们知道平时我们都会做字符串拼接打印操作,单还是在用?号嘛,那样就很low为力显示逼格,使用format操作很有必要??String类的format()方法用于创建格式化的字符串以及连接...
在输出日期信息时,经常需要输出不同格式的日期格式,本实例中介绍了<SPAN style=‘font-family: "Times New Roman";‘>String字符串类中的日期格式化方法,实例使用不同的方式输出
"Times New Roman";‘>String类的日期格式参数值,组合这些值可以实现特殊格式的日期字符串。思路如下:比如要输出月份的英文简称,通过<SPAN
style=‘font-family: "Times New Roman";‘>String类的<SPAN
style=‘font-family: "Times New Roman"...
转自:JAVA字符串格式化-String.format()的使用(转) 常规类型的格式化String类的format()方法用于创建格式化的字符串以及连接多个字符串对象。熟悉C语言的同学应该记得C语言的sprintf()方法,两者有类似之处。format()方法有两种重载形式。format(String format, Object... args) 新字符串使用本地语言环境,制定字符串格式和参数生成格式化的新字符串。format(Locale locale, String format, Object... args) 使用指定的语言环境...
1、使用Date对象 String dateStr = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date());2、使用Calendar对象 String dateStr = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(Calendar.getInstance().getTime());3、使用LocalDateTime对象String dateStr = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss"));原文:https://www.cnblogs.com/will-666/p/11399190.html
1.相关扩展函数//---------------------------------------------------
// 判断闰年
//---------------------------------------------------
Date.prototype.isLeapYear = function()
{return (0==this.getYear()%4&&((this.getYear()%100!=0)||(this.getYear()%400==0)));
};//---------------------------------------------------
// 日期格式化
// 格式 YYYY/yyyy/YY/yy 表示年份
// MM/M 月份
// W/w 星期
// dd/DD/d/D 日期...
import java.util.Date;
import java.text.DateFormat;/**
* 格式化时间类
* DateFormat.FULL = 0
* DateFormat.DEFAULT = 2
* DateFormat.LONG = 1
* DateFormat.MEDIUM = 2
* DateFormat.SHORT = 3
* @author Michael
* @version 1.0, 2007/03/09
*/public class Test{
public static void main(String []args){
Date d = new Date();
String s;
/** Date类的格式: Sat Apr 16 13...
本文转载地址http://www.cnblogs.com/zhangpengshou/archive/2012/07/19/2599053.html // 对Date的扩展,将 Date 转化为指定格式的String
// 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符,
// 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
// 例子:
// (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
// (new Date()).Format("yyyy-M-d h:m:s.S...
转:http://blog.csdn.net/lonely_fireworks/article/details/7962171/常规类型的格式化String类的format()方法用于创建格式化的字符串以及连接多个字符串对象。熟悉C语言的同学应该记得C语言的sprintf()方法,两者有类似之处。format()方法有两种重载形式。format(String format, Object... args) 新字符串使用本地语言环境,制定字符串格式和参数生成格式化的新字符串。format(Locale locale, String format, Object... args) 使...
转:http://blog.sina.com.cn/s/blog_af26e3330101988v.html1.对整数进行格式化:%[index$][标识][最小宽度]转换方式 我们可以看到,格式化字符串由4部分组成,其中%[index$]的含义我们上面已经讲过,[最小宽度]的含义也很好理解,就是最终该整数转化的字符串最少包含多少位数字。我们来看看剩下2个部分的含义吧: 标识: ‘-‘ 在最小宽度内左对齐,不可以与“用0填充”同时使用 ‘#‘ 只适用于8进制和16进制,8进...
在做java开发的时候,经常要格式化java对象,闲来无事就写了一个,如果传递的是单个对象生成数据格式 {"id":"1","name":"名字"}传递的是list对象生成数据格式 [{"id":"1","name":"名字"},{"id":"2","name":"名字2"}]暂时还不支持对象递归生成数据 public class JsonUtil {public static String toJson(Object obj){StringBuffer json = new StringBuffer();if(obj instanceof Collection){json.append("[");Collection objColl =...
int x = 1;while(x<100){DecimalFormat df = new DecimalFormat("000");String xs = df.format(x);System.out.println(xs);x++;}将 1 格式化为 001原文:http://www.cnblogs.com/lipeil/p/4847175.html
Format该类是个抽象基类,具体子类必须实现://将对象格式化为指定模式的字符串
format(Object obj, StringBuffer toAppendTo, FieldPosition pos)//将字符串重新解析为对象
parseObject(String source, ParsePosition pos)DateFormat(格式化日期时间)DateFormat根据当前语言环境格式化日期和时间。DateFormat是一个抽象类,所以不能直接new创建实例对象。但该类为我们提供了工厂方法方便我们使用。getDateInstance() ——获取格...
Eclipse代码格式化-代码模板 eclipse 代码模板_百度搜索编码规范系列(一):Eclipse Code Templates设置 - 青葱岁月 - ITeye博客善用Eclipse的代码模板功能 - 51CTO.COM如何修改Eclipse的代码模板-CSDN论坛Eclipse Java注释模板设置详解 - CSDN博客善用Eclipse的代码模板功能 - 51CTO.COMxml 格式化_百度搜索在线代码格式化原文:https://www.cnblogs.com/junneyang/p/8267174.html
java 获取系统当前时间并格式化CreateTime--2018年5月9日11:41:00Author:Marydon实现方式有两种import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;/*** 获取系统当前时间* @descrition 使用Calendar实现* @param format* @return*/public String getSysdateStr (String format) {Date sysdate = Calendar.getInstance().getTime();format = "".equals(format)?"yyyy-MM-dd HH:mm:ss":format;S...
使用SimpleDateFormat来实现格式化日期import java.text.SimpleDateFormat;
import java.util.Date;publicclass DateFormatExample {publicstaticvoid main(String args[]) {Date today = new Date();System.out.println("今天 is : " + today);SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd-MM-yyyy");String date = DATE_FORMAT.format(today);System.out.println("今天 in dd-MM-yyyy format : " + date);DATE_FORM...