编写智能合约收集的一些小知识

1.uint 转string:edureka!

function uint2str(uint i) internal pure returns (string){
    if (i == 0) return "0";
    uint j = i;
    uint length;
    while (j != 0){
        length++;
        j /= 10;
    }
    bytes memory bstr = new bytes(length);
    uint k = length - 1;
    while (i != 0){
        bstr[k--] = byte(48 + i % 10);
        i /= 10;
    }
    return string(bstr);
}

2.string拼接:
https://blog.csdn.net/shebao3333/article/details/80077939

contract EzDemo {
    function strConcat(string _a, string _b) internal returns (string){
        bytes memory _ba = bytes(_a);
        bytes memory _bb = bytes(_b);
        string memory ret = new string(_ba.length + _bb.length + _bc.length + _bd.length + _be.length);
        bytes memory bret = bytes(ret);
        uint k = 0;
        for (uint i = 0; i < _ba.length; i++)bret[k++] = _ba[i];
        for (i = 0; i < _bb.length; i++) bret[k++] = _bb[i];
        return string(ret);
   }  
}

3.用Java求两个日期之间相差的秒数:https://blog.csdn.net/thjoin/article/details/46229609

import java.util.*;
public class Main {

    public static void main(String[] args) {
        Calendar calendar1 = Calendar.getInstance();

        calendar1.set(1970, 0, 1,0,0,0);
        TimeZone tz = TimeZone.getTimeZone("GMT");

        Calendar calendar2 = Calendar.getInstance();
        calendar2.set(2019,5,1,0,0,0);

//        calendar.setTimeZone(tz); // 注意,此处设置时区,不然会有8小时的误差

        long t1 = calendar1.getTimeInMillis();

        long t2 = calendar2.getTimeInMillis();

        int t3 = (int)((t2-t1)/1000);
        System.out.println(t3);

    }
}

4.粗略转时间:
1)从1970-01-01到2019-06-01,一共过了12366+37365+31+28+31+30+31=18048天,一共1559347200秒
2)一天是86400秒
3)6月有30天,一共259200秒

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值