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秒