当前位置:网站首页>Various programming languages decimal | time | Base64 and other operations of the quick look-up table
Various programming languages decimal | time | Base64 and other operations of the quick look-up table
2022-07-28 06:07:00 【Alex_ z0897】
Switch between languages , At this time, a bad pen is better than a good memory . Sort out the processing of rounding decimals in various languages , String and time are exchanged ,base And so on ,
Round to two decimal places
# 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)
String to time
# 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)
Time to string
# python
datetime.strftime()
datetime.now().strftime("%Y-%m-%d %X")
# java
String str = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
//LocalDateTime form
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(new LocalDateTime());
# golang
time.Now().Format("2006-01-02"),
File transfer 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 code
# java
Base64.getEncoder().encodeToString((str).getBytes())
base64 decode
# java
Base64.getDecoder().decode(data)
Get the current timestamp
# java
new Date().time();
# golang
timeUnixNano:=time.Now().UnixNano()
# dart
new DateTime.now().millisecondsSinceEpoch
# python
datetime.now().timestamp()
turn 13 A time stamp
# python Version is 2.7.~ The old version
# Current time conversion
struct_time = datetime.now().timetuple()
print(int(round(time.mktime(struct_time)* 1000)))
# String conversion
struct_time = time.strptime("2021-10-15 11:04:19", "%Y-%m-%d %H:%M:%S")
print(int(round(time.mktime(struct_time)* 1000)))
Continuous updating …
边栏推荐
猜你喜欢

高端大气的小程序开发设计有哪些注意点?

深度学习——MetaFormer Is Actually What You Need for Vision

There is a problem with MySQL paging

面试官:让你设计一套图片加载框架,你会怎么设计?

XShell突然间无法连接虚拟机

【六】redis缓存策略

Micro service architecture cognition and service governance Eureka

On how digital collections and entities can empower each other

小程序制作小程序开发适合哪些企业?

服务可靠性保障-watchdog
随机推荐
Manually create a simple RPC (< - < -)
Mars number * word * Tibet * product * Pingtai defender plan details announced
深度学习——MetaFormer Is Actually What You Need for Vision
Quick look-up table to MD5
self-attention学习笔记
2: Why read write separation
flutter webivew input唤起相机相册
速查表之转MD5
小程序开发解决零售业的焦虑
Chapter IX sub query (key)
Micro service architecture cognition and service governance Eureka
Idempotent component
On July 7, the national wind 24 solar terms "Xiaoshu" came!! Attachment.. cooperation.. completion.. advance.. report
区分实时数据、离线数据、流式数据以及批量数据的区别
字节Android岗4轮面试,收到 50k*18 Offer,裁员风口下成功破局
项目不报错,正常运行,无法请求到服务
接口防重复提交
手撸一个简单的RPC(<-_<-)
ModuleNotFoundError: No module named ‘pip‘
【六】redis缓存策略