Power Automate里的常用方法

本文介绍了JavaScript中用于数学运算(如整数除法、取余)、数字格式化、时间戳处理(获取ticks值、计算日期差)以及时区转换的内置函数:div(),mod(),sub(),formatNumber(),ticks(),和convertFromUtc(),展示了它们的用法和示例。
摘要由CSDN通过智能技术生成

 1、div() 返回两个数相除的整数部分

div(dividend: number, divisor: number)

Required. The number to divide by the Divisor.

Returns the result from dividing the two number

div(7, 2) // 返回结果: 3
div(6, 4) // 返回结果: 1

 2、mod() 返回两个数相除的余数部分

mod(dividend: number, divisor: number)

Required. The number to divide by the Divisor.

Returns the remainder after dividing the two numbers (modulo)

mod(3, 2) // 返回结果: 1
mod(7, 4) // 返回结果: 3

 3、sub() 返回两个数相减的结果。

sub(minuend: number, subtrahend: number)

Required. The number that Subtrahend is removed from.

Returns the result from subtracting two numbers

sub(7, 5) // 返回结果: 2

  4、formatNumber() 格式化number

formatNumber(number: number, format: string, locale?: string)

Required. The number to be formatted.

Returns a formatted number string

formatNumber(float('10000.666666'), 'C2') 
// 返回结果: $10,000.67  C: '$' 2: 保留两位小数

5、ticks() 返回指定时间的ticks值

ticks(timestamp: string)

Required. This is a string that contains the time.

Returns the number of ticks (100 nanoseconds interval) since 1 January 0001 00:00:00 UT of a string timestamp

ticks('2024-04-03')
// 返回结果: 638476992000000000

// 计算俩个日期之间的天数
div(sub(ticks('2024-04-03'),ticks(outputs('2024-04-01'))),864000000000)
// 返回结果: 2

 864000000000 => the number of ticks in a day

 864000000000的计算过程:

1 day = 24 hours/day * 60 minutes/hour * 60 seconds/minute * 1,000,000,000 nanoseconds/second 1 day = 86,400,000,000,000 nanoseconds

1 day = 86,400,000,000,000 nanoseconds / (100 nanoseconds/tick) 1 day = 864,000,000,000 ticks

6、convertFromUtc() 将某个UTC时间转化成指定时区的指定格式的时间。 

convertFromUtc(timestamp: string, destinationTimeZone: string, format?: string)

Required. A string that contains the time.

Converts a string timestamp passed in from a UTC to a target time zone

convertFromUtc(utcNow(), 'Singapore Standard Time', 'yyyy-MM-dd')
// 返回结果: 2024-04-03

 destinationTimeZone: target time zone url

Time Zone Abbreviations - Worldwide List

formatRule url 

Standard date and time format strings - .NET | Microsoft Learn

  • 20
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值