当前位置:网站首页>速查表之各种编程语言小数|时间|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)))
持续更新…
边栏推荐
猜你喜欢

小程序开发哪家更靠谱呢?

Create a virtual environment using pycharm

2:为什么要读写分离

Distributed lock database implementation

万变不离其宗-掌控者靶场之bluecms1.6漏洞

微信小程序手机号正则校验规则

【2】 Redis basic commands and usage scenarios

【5】 Redis master-slave synchronization and redis sentinel (sentinel)

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

微信团购小程序怎么做?一般要多少钱?
随机推荐
撞脸ins? Mars数字藏品平台探索数字藏品轻社交
分布式集群架构场景优化解决方案:Session共享问题
XML parsing entity tool class
1: Why should databases be divided into databases and tables
Hit your face ins? Mars digital collection platform explores digital collection light social networking
1:开启慢查询日志 与 找到慢SQL
Wechat official account - authorized login
No module named yum
Flume installation and use
Use Python to encapsulate a tool class that sends mail regularly
Notice of attack: [bean Bingbing] send, sell, cash, draw, prize, etc
Books - poor Charlie's classic
Kotlin语言现在怎么不火了?你怎么看?
浅拷贝、深拷贝区别
区分实时数据、离线数据、流式数据以及批量数据的区别
单行函数,聚合函数课后练习
trino函数随记
Assembly packaging
Distinguish between real-time data, offline data, streaming data and batch data
Mars数*字*藏*品*平*台守卫者计划细节公布