当前位置:网站首页>速查表之各种编程语言小数|时间|base64等操作
速查表之各种编程语言小数|时间|base64等操作
2022-07-28 05:22:00 【Alex_z0897】
在各种语言之间切换,这时候好记性不如烂笔头. 整理下各种语言四舍五入小数的处理, 字符串与时间互相换转,base等相关操作,
四舍五入保留两位小数
# js
"12.125".toFixed(2)
#python
print("%.2f" % a)
# mysql
select round(a,2)
#golang
value = math.Trunc(value*1e2+0.500000001) * 1e-2
result, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", value), 64)
#java
BigDecimal value = value1.setScale(2,RoundingMode.HALF_UP)
字符串转时间
# python
datetime.strptime(start_time, "%Y-%m-%d %H:%M")
# java
Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(str)
# golang
sd, _ := time.Parse("2006-01-02", start)
时间转字符串
# python
datetime.strftime()
datetime.now().strftime("%Y-%m-%d %X")
# java
String str = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
//LocalDateTime形式
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(new LocalDateTime());
# golang
time.Now().Format("2006-01-02"),
文件转base64
# dart(flutter)
var image = File(picPath);
var startDate = new DateTime.now();
List<int> imageBytes = await image.readAsBytes();
var fileBase64 = 'data:image/jpeg;base64,'+base64Encode(imageBytes);
base64编码
# java
Base64.getEncoder().encodeToString((str).getBytes())
base64解码
# java
Base64.getDecoder().decode(data)
获取当前时间戳
# java
new Date().time();
# golang
timeUnixNano:=time.Now().UnixNano()
# dart
new DateTime.now().millisecondsSinceEpoch
# python
datetime.now().timestamp()
转13位时间戳
# python版本为2.7.~ 老版本
# 当前时间转换
struct_time = datetime.now().timetuple()
print(int(round(time.mktime(struct_time)* 1000)))
#字符串转换
struct_time = time.strptime("2021-10-15 11:04:19", "%Y-%m-%d %H:%M:%S")
print(int(round(time.mktime(struct_time)* 1000)))
持续更新…
边栏推荐
- Installation and use of sqoop
- The combination of cultural tourism and digital collections has a significant effect, but how to support users' continuous purchasing power
- 分布式锁-Redis实现
- Distributed lock redis implementation
- 万变不离其宗-掌控者靶场之bluecms1.6漏洞
- 1: Why should databases be divided into databases and tables
- JS simple publish and subscribe class
- Create a virtual environment using pycharm
- 疫情当下,线下文旅受困,看数字藏品能否解围?
- 幂等性组件
猜你喜欢

文件上传漏洞总结

【7】 Consistency between redis cache and database data

The project does not report an error, operates normally, and cannot request services

数据仓库工具superset安装(完全可用)

手撸一个简单的RPC(<-_<-)

预告来袭:【豆冰冰】发.售,现.金.抽.奖等你来拿

mysql分页出现问题

DataX installation and use

On how digital collections and entities can empower each other

Xshell suddenly failed to connect to the virtual machine
随机推荐
Chapter 7 single line function
【3】 Redis features and functions
发售预告:7月22日“大暑”发售,【传统国风廿四节气】夏季发售完毕。
【五】redis主从同步与Redis Sentinel(哨兵)
Assembly packaging
Tiktok - VIDEO steps
Sqoop安装及使用
Use Python to encapsulate a tool class that sends mail regularly
微信小程序开发语言一般有哪些?
初识Flask
区分实时数据、离线数据、流式数据以及批量数据的区别
Books - the art of lucid thinking
On July 7, the national wind 24 solar terms "Xiaoshu" came!! Attachment.. cooperation.. completion.. advance.. report
CertPathValidatorException:validity check failed
小程序搭建制作流程是怎样的?
mysql5.6(根据.ibd,.frm文件)恢复单表数据
MySQL multi table query
1: Why should databases be divided into databases and tables
浅拷贝、深拷贝区别
记录下在线扩容服务器遇到的问题 NOCHANGE: partition 1 is size 419428319. it cannot be grown