1 将系统时间转换成unix时间戳
datetime dtstart = timezone.currenttimezone.tolocaltime(new datetime(1970,1,1));
datetime dtnow = datetime.parse(datetime.now.tostring());
timespan tonow = dtnow.subtract(dtstart);
string timestamp = tonow.ticks.tostring();
timestamp = timestamp.substring(0,timestamp.length - 7);
2将unix时间戳转换成系统时间
string timestamp = "1144821796";
datetime dtstart = timezone.currenttimezone.tolocaltime(new datetime(1970,1,1));
long ltime = long.parse(timestamp + "0000000");
timespan tonow = new timespan(ltime);
datetime dtresult = dtstart.add(tonow);
//datetime轉變為unix時間,直接转换,不改变时区
datetime dtstart = new datetime(1970, 1, 1, 0, 0, 0);
timespan tonow = dt.subtract(dtstart);
int timestamp = (int)(tonow.ticks/10000000);
新闻热点
疑难解答