当前位置:网站首页>常用类的小知识
常用类的小知识
2022-07-25 09:27:00 【看小虫子】
StringBuffer
StringBuffer sb=new StringBuffer();
//1,append追加
sb.append("kankan");
//2,insert()添加或插入
sb.insert(0,12);
//3,replace()替换
sb.replace(0,2,"world");
//4,delete 删除
sb.delete(0,2);
System.out.println(sb.toString());
Calendar类的使用
Calendar calendar=Calendar.getInstance();
System.out.println(calendar.getTime().toLocaleString());//获得当前时间
System.out.println(calendar.getTimeInMillis());//从1970年一月一到现在的毫秒数
//获取年月日
int year=calendar.get(calendar.YEAR);
int month=calendar.get(calendar.MONTH); //从0-11开始
int day=calendar.get(calendar.DAY_OF_MONTH);
int hour=calendar.get(calendar.HOUR_OF_DAY);
int minute=calendar.get(calendar.MINUTE);
int second=calendar.get(calendar.SECOND);
System.out.println(year+"年"+month+"月"+day+"日"+hour+"时"+minute+"分"+second);
//修改时间
Calendar calendar2=Calendar.getInstance();
calendar2.set(calendar.DAY_OF_MONTH,19) ;//将天数设为19
System.out.println(calendar2.getTime().toLocaleString());
//add方法修改时间
calendar2.add(calendar.HOUR,1); //将小时数加一,减法可以直接输入负数
System.out.println(calendar2.getTime().toLocaleString());
simpleDateFormate类
//用SimpleDateFormat类将Date转化为字符串
SimpleDateFormat sdf=new SimpleDateFormat("yyy年MM月dd日 HH:mm:ss");
//2,创建一个Date
Date date=new Date();
//将日期转化为字符串
String str =sdf.format(date);
System.out.println(str);
边栏推荐
- Probabilistic robot learning notes Chapter 2
- Round to the nearest
- File upload function
- yarn速查手册
- Detailed explanation of JDBC operation database
- 严重 [main] org.apache.catalina.util.LifecycleBase.handleSubClassException 初始化组件
- 力扣刷题组合问题总结(回溯)
- 关闭brew执行命令时的自动更新
- Record of deep learning segment error (segment core/ exit code 139)
- oh-my-zsh和tmux配置(个人)
猜你喜欢

小程序分享功能

数据库MySQL详解

@Import,Conditional和@ImportResourse注解

@Import, conditional and @importresource annotations
![[recommended collection] with these learning methods, I joined the world's top 500 - the](/img/95/e34473a1628521d4b07e56877fcff1.png)
[recommended collection] with these learning methods, I joined the world's top 500 - the "fantastic skills and extravagance" in the Internet age

Configuring ROS development environment with vscode: Causes and solutions to the problem of ineffective code modification

GCD详解

UE4 快速找到打包失败的原因

Use of dictionary tree

DHCP的配置(以华为eNSP为例)
随机推荐
Introduction to arm GIC
NPM details
CentOs安装redis
UE4 碰撞(Collsion)
数论--负进制转换
小程序分享功能
多数相合问题总结
小程序企业发放红包功能
struct2的原理
[necessary for growth] Why do I recommend you to write a blog? May you be what you want to be in years to come.
Arm preliminaries
The economic basis of a hardware siege lion
yarn速查手册
ES6 detailed explanation
字典树的使用
Dataset 和 Dataloader数据加载
Nodejs初体验
UE4 外部打开exe文件
力扣刷题组合问题总结(回溯)
GUI窗口