工作笔记5
Posted 望峰游云
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了工作笔记5相关的知识,希望对你有一定的参考价值。
1、js 时间转化为几天前、几小时前、几分钟前
function getDateDiff(dateTimeStamp){ var minute = 1000 * 60; var hour = minute * 60; var day = hour * 24; var halfamonth = day * 15; var month = day * 30; var now = new Date().getTime(); var diffValue = now - dateTimeStamp; if(diffValue < 0){return;} var monthC =diffValue/month; var weekC =diffValue/(7*day); var dayC =diffValue/day; var hourC =diffValue/hour; var minC =diffValue/minute; if(monthC>=1){ result="" + parseInt(monthC) + "月前"; } else if(weekC>=1){ result="" + parseInt(weekC) + "周前"; } else if(dayC>=1){ result=""+ parseInt(dayC) +"天前"; } else if(hourC>=1){ result=""+ parseInt(hourC) +"小时前"; } else if(minC>=1){ result=""+ parseInt(minC) +"分钟前"; }else result="刚刚"; return result; }
C# 时间转化为几天前、几小时前、几分钟前
private string GetDateDiff(int dateTimeStamp) { string result = string.Empty; var minute = 60; var hour = minute * 60; var day = hour * 24; var halfamonth = day * 15; var month = day * 30; var now = GetTimeStamp(); var diffValue = now - dateTimeStamp; if (diffValue < 0) { return ""; } var monthC = diffValue / month; var weekC = diffValue / (7 * day); var dayC = diffValue / day; var hourC = diffValue / hour; var minC = diffValue / minute; if (monthC >= 1) { result = "" + Convert.ToInt32(monthC) + "月前"; } else if (weekC >= 1) { result = "" + Convert.ToInt32(weekC) + "周前"; } else if (dayC >= 1) { result = "" + Convert.ToInt32(dayC) + "天前"; } else if (hourC >= 1) { result = "" + Convert.ToInt32(hourC) + "小时前"; } else if (minC >= 1) { result = "" + Convert.ToInt32(minC) + "分钟前"; } else { result = "刚刚"; } return result; } public Int64 GetTimeStamp() { TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
//去掉毫秒数 var time = ts.TotalMilliseconds.ToString().Substring(0, 10); return Convert.ToInt64(time); }
以上是关于工作笔记5的主要内容,如果未能解决你的问题,请参考以下文章
Unity Shader入门精要学习笔记 - 第5章 开始 Unity Shader 学习之旅