DateTime
2015-06-23 18:48
190 查看
//时间、数值工具类//
public class _Utility:MonoBehaviour{
void Start () {
}
void Update () {
}
public class _Utility:MonoBehaviour{
void Start () {
}
void Update () {
}
public static int getDstNum(int num) { return (num+198012)^654321; } public static int getSrcNum(int num) { return (num^654321)-198012; } //日期相关*******************************************************************************************************************// //现在到1970的时间,精确到毫秒// //static Stopwatch stopwatch = new Stopwatch(); public static double currentTimeMillis() { TimeSpan ts=DateTime.UtcNow - DateTime.Parse("1970-1-1"); return ts.TotalMilliseconds; } //获得当前时间DateTime对象// public static System.DateTime getTime() { //System.DateTime.Now//本地时间,12小时制的// //System.DateTime.Now.ToString("yyyyMMddHHmmss")//军事日期时间// //System.DateTime.UtcNow//UTC时间// //GUILayout.SelectionGrid(System.DateTime.Now.Month-1,Months,3); //GUILayout.SelectionGrid(System.DateTime.Now.Day-1,Days,10); //GUILayout.Box(str+dNow.Now.Year+"年"+dNow.Now.Month+"月"+dNow.Now.Day+" 日"+" "+dNow.Now.Hour+"时"+dNow.Now.Minute+"分"+dNow.Now.Second+"秒"); System.DateTime now = System.DateTime.Now; return now; } //返回当前时间与oldTime的时间差,以秒为单位// public static System.TimeSpan getSpanTime(System.DateTime oldTime) { System.TimeSpan span = getTime() - oldTime; return span; } //返回当前时间与oldTime的时间差,以秒为单位// public static int getSpanTimeSeconds(System.DateTime oldTime) { System.TimeSpan span = getTime() - oldTime; return (int)span.TotalSeconds; } //当前时间到未来一个时间,还剩多少时间// public static System.TimeSpan getRemainTime(System.DateTime futureTime) { System.TimeSpan remain = futureTime - getTime(); return remain; } //DateTime转换为19700101,单位 秒// public static double ConvertDateTime2Int(System.DateTime time) { double intResult = 0; System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); intResult = (time - startTime).TotalSeconds; return intResult; } //19700101,单位 秒转换为DateTime// public static System.DateTime ConvertInt2DateTime(double d) { System.DateTime time = System.DateTime.MinValue; System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); time = startTime.AddSeconds(d); return time; } //判断是不是今天// public static bool timeIsToday(long time) { //+8时区// double curTime = currentTimeMillis() / 1000; //curTime += 8*3600; DateTime date = ConvertInt2DateTime (time); DateTime curdate = ConvertInt2DateTime (curTime); if(date.Year == curdate.Year && date.Month == curdate.Month && date.Day == curdate.Day) { return true; } return false; } //判断是不是过了cd,参数cd,精度,次数,时间偏移,被比较的时间// public static bool isCrossResetPoint(int cd,int accuracy,int count,int offset,int lastSecond) { double curTime = currentTimeMillis() / 1000; int cur = (int)(curTime - offset); int last = lastSecond - offset; if (accuracy == 1) //精度1秒// { if((cur - last) >= cd * accuracy) { return true; } }else if(accuracy == 86400)//精度1天// { if(timeIsToday(lastSecond)) { return false; }else { return true; } }else//精度其他// { return false; } return false; } //某个日期是否 > 某个日期// public static bool IsGreaterDate(DateTime myDate, DateTime compareDate) { return myDate.CompareTo(compareDate) >= 0; } //某个日期是否 < 某个日期// public static bool IsSmallerDate(DateTime myDate, DateTime compareDate) { return myDate.CompareTo(compareDate) <= 0; }
相关文章推荐
- Mysql权限设置
- 【线段树】 HDOJ 5274 Dylans loves tree
- 第四章
- 【ContestHunter】【弱省胡策】【Round8】
- android 返回本机安装的所有第三方应用
- 串行化(序列化) 使用CArchive进行读写
- Objective-C与C++的区别
- Android学习第四课:Java代码动态创建View及LayoutParams类(二)
- select加载数据和数据选中
- xargs
- 我的大学六年(单片机大师郭天祥原创)
- 使用HttpSessionListener接口监听Session的创建和失效
- /mnt/asec /mnt/secure文件夹分区
- 约瑟夫环的数学推导、数学方法求最后出圈的数字、循环单链表求所有出圈数字顺序
- Android 刷脸神器,颜值价更高
- B. Vanya and Books
- windows下同步方案-cwRsync
- 车牌
- QQ智能聊天机器人设想
- 应用启动 ActivityStackSupervisor分析