Browse Source

时间格式化工具

zhaoyang 3 years ago
parent
commit
51078c7bcd

+ 1 - 1
FGUIProject/assets/LuckyBox/components/ComListBgItem.xml

@@ -10,7 +10,7 @@
     <graph id="n31_qi04" name="holder1" xy="697,779" size="100,100">
       <relation target="" sidePair="top-middle"/>
     </graph>
-    <text id="n28_vek8" name="txtTime" xy="324,409" size="80,902" fontSize="40" color="#fffbdd" align="center" vAlign="middle" autoSize="none" text="剩余81天">
+    <text id="n28_vek8" name="txtTime" xy="324,409" size="70,902" fontSize="40" color="#fffbdd" align="center" vAlign="middle" ubb="true" autoSize="none" text="剩余811小时">
       <relation target="" sidePair="height-height,top-top"/>
     </text>
     <graph id="n30_qi04" name="holder" xy="312,700" size="100,100">

+ 1 - 1
GameClient/Assets/Game/CSShare

@@ -1 +1 @@
-Subproject commit 2a173aab555881ac18160435e6a09cffe2ebf78a
+Subproject commit 94d5327b9ee7c302ab42dd243b4a89eec168babb

+ 0 - 89
GameClient/Assets/Game/HotUpdate/Utils/DateUtils.cs

@@ -1,89 +0,0 @@
-using System;
-using System.Collections;
-using UnityEngine;
-
-namespace GFGGame
-{
-    public class DateUtils : SingletonBase<DateUtils>
-    {
-
-        public const int TIME_FORMAT_1 = 1;
-
-        public int MONTH_PER_YEAR = 12;//每年的月数
-        public int DAYS_PER_MONTH = 30;//每月的天数
-        public int HOURS_PER_DAY = 24;//每天的小时数
-        public int MUNITE_PER_HOUR = 60;//每小时的分钟数
-        public int SECOND_PER_MUNITE = 60;//每分钟的秒数
-        public int SECOND_PER_DAY = 86400;//一天的秒数
-        public int GetCurTime()
-        {
-            var utcNow = DateTime.UtcNow;
-            var timeSpan = utcNow - new DateTime(1970, 1, 1, 0, 0, 0);
-
-            return (int)timeSpan.TotalSeconds;
-        }
-        //direction排版方向:0横向,1纵向
-        public string getFormatBySecond(int second, int type = 1, int direction = 0)
-        {
-            string str = "";
-            int ms = second * 1000;
-            switch (type)
-            {
-                case DateUtils.TIME_FORMAT_1:
-                    str = this.format_1(second, direction);
-                    break;
-            }
-            return str;
-        }
-        //剩余时间大于1天返回天数,小于一天返回小时数,小于一小时返回分钟数,小于1分钟返回秒数
-        public string format_1(int second, int direction = 0)
-        {
-            if (second / this.SECOND_PER_DAY >= 1)
-            {
-                if (direction == 0)
-                {
-                    return string.Format("剩余{0}天", Mathf.Floor(second / this.SECOND_PER_DAY));
-                }
-                else
-                {
-                    return string.Format("剩\n余\n{0}\n天", Mathf.Floor(second / this.SECOND_PER_DAY));
-                }
-            }
-            else if (second / this.SECOND_PER_DAY < 1 && second / (this.MUNITE_PER_HOUR * this.SECOND_PER_MUNITE) >= 1)
-            {
-                if (direction == 0)
-                {
-                    return string.Format("剩余{0}小时", Mathf.Floor(second / (this.MUNITE_PER_HOUR * this.SECOND_PER_MUNITE)));
-
-                }
-                else
-                {
-                    return string.Format("剩\n余\n{0}\n小\n时", Mathf.Floor(second / (this.MUNITE_PER_HOUR * this.SECOND_PER_MUNITE)));
-                }
-            }
-            else if (second / this.SECOND_PER_DAY < 1 && second / (this.MUNITE_PER_HOUR * this.SECOND_PER_MUNITE) < 1 && second / this.SECOND_PER_MUNITE >= 1)
-            {
-                if (direction == 0)
-                {
-                    return string.Format("剩余{0}分钟", Mathf.Floor(second / this.SECOND_PER_MUNITE));
-                }
-                else
-                {
-                    return string.Format("剩\n余\n{0}\n分\n钟", Mathf.Floor(second / this.SECOND_PER_MUNITE));
-                }
-            }
-            else if (second < this.SECOND_PER_MUNITE)
-            {
-                if (direction == 0)
-                {
-                    return string.Format("剩余{0}秒", second);
-                }
-                else
-                {
-                    return string.Format("剩\n余\n{0}\n秒", second);
-                }
-            }
-            return "";
-        }
-    }
-}

+ 26 - 0
GameClient/Assets/Game/HotUpdate/Utils/TimeUtil.cs

@@ -0,0 +1,26 @@
+using System;
+using System.Collections;
+using UnityEngine;
+
+namespace GFGGame
+{
+    public partial class TimeUtil : SingletonBase<TimeUtil>
+    {
+        public static string FormattingTime(int curTime, int endTime)
+        {
+            int time = endTime - curTime;
+
+            int hours = (int)Math.Floor((decimal)time / TimeUtil.SECOND_PER_HOUR);
+            if (hours >= 1)
+            {
+                return string.Format("{0}小时", hours);
+            }
+            int minutes = (int)Math.Floor((decimal)time / TimeUtil.SECOND_PER_MUNITE);
+            if (minutes >= 1)
+            {
+                return string.Format("{0}分钟", minutes);
+            }
+            return string.Format("{0}秒", minutes);
+        }
+    }
+}

+ 1 - 1
GameClient/Assets/Game/HotUpdate/Utils/DateUtils.cs.meta → GameClient/Assets/Game/HotUpdate/Utils/TimeUtil.cs.meta

@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: 5f0b81650b4637446abe2dd505a43826
+guid: 4771a2705424e2d4d9c856fc6686eaad
 MonoImporter:
   externalObjects: {}
   serializedVersion: 2

+ 2 - 1
GameClient/Assets/Game/HotUpdate/Views/DressUp/PhotographSaveView.cs

@@ -1,6 +1,7 @@
 using System;
 using System.Collections;
 using System.IO;
+using ET;
 using FairyGUI;
 using UI.DressUp;
 using UnityEngine;
@@ -62,7 +63,7 @@ namespace GFGGame
 
                 }
             }
-            string fileName = "wsj" + DateUtils.Instance.GetCurTime() + ".jpg";
+            string fileName = "wsj" + TimeHelper.ServerNowSecs + ".jpg";
 
             Texture2D tex = this.viewData as Texture2D;
             byte[] bytes = tex.EncodeToJPG();//将纹理数据,转化成一个jpg图片

+ 3 - 2
GameClient/Assets/Game/HotUpdate/Views/LuckyBox/LuckyBoxView.cs

@@ -4,6 +4,7 @@ using UI.CommonGame;
 using System;
 using System.Collections.Generic;
 using UnityEngine;
+using ET;
 
 namespace GFGGame
 {
@@ -109,8 +110,8 @@ namespace GFGGame
                 return;
             }
             int endTime = LuckyBoxDataManager.Instance.endTime;
-            int curTime = DateUtils.Instance.GetCurTime();
-            UI_ComListBgItem.Proxy(_ui.m_listBg.GetChildAt(0)).m_txtTime.text = DateUtils.Instance.getFormatBySecond(endTime - curTime, 1, 1);
+            int curTime = TimeHelper.ServerNowSecs;
+            UI_ComListBgItem.Proxy(_ui.m_listBg.GetChildAt(0)).m_txtTime.text = string.Format("剩余\n{0}", TimeUtil.FormattingTime(curTime, endTime));
         }
         private void OnListBgScroll()
         {

BIN
GameClient/Assets/ResIn/UI/LuckyBox/LuckyBox_atlas0!a.png


BIN
GameClient/Assets/ResIn/UI/LuckyBox/LuckyBox_atlas0.png


BIN
GameClient/Assets/ResIn/UI/LuckyBox/LuckyBox_fui.bytes