将数据库时间戳转换为时间

时间:2020-08-16 23:10:30

标签: flutter dart

我要从数据库中提取一个timeStamp,其值基本上与此2020-08-13 21:51:50相似,是否可以将timeStamp转换为以前的时间?

2 个答案:

答案 0 :(得分:0)

您可以使用timeago软件包。

def factor_range(n):
    is_prime = [True for i in range(n+1)]
    factorization = {}
    
    for p in range(2, n+1):
        if is_prime[p]:
            power = p
            factors = 0
            while power <= n:
                s = power
                while s <= n:
                    factors = factors + 1
                    is_prime[s] = 0
                    s = s + power
                power = power * p
            factorization[p] = factors
    return factorization

答案 1 :(得分:0)

JideGuru在使用timeago软件包方面是正确的;但是,如果要从MySQL数据库提取时间戳,则可能需要先将其转换为toDate

import 'package:timeago/timeago.dart' as timeago;

var rawTime = mySQLTimestamp.toDate();
String timeAgoTime = timeago.format(rawTime);