将毫秒转化成时分秒

        //将毫秒转换成时分秒
        public string formatLongToTimeStr(long a)
        {
            try
            {
                int hour = 0;
                int minute = 0;
                int second = 0;

                second = Convert.ToInt32(a) / 1000;

                if (second > 60)
                {
                    minute = second / 60;
                    second = second % 60;
                }
                if (minute > 60)
                {
                    hour = minute / 60;
                    minute = minute % 60;
                }
                var newHour = string.Empty;
                if (Convert.ToString(hour).Length < 2)
                {
                    newHour = "0" + Convert.ToString(hour);
                }
                else
                {
                    newHour = Convert.ToString(hour);
                }
                var newMinute = string.Empty;
                if (Convert.ToString(minute).Length < 2)
                {
                    newMinute = "0" + Convert.ToString(minute);
                }
                else
                {
                    newMinute = Convert.ToString(minute);
                }
                var newSecond = string.Empty;
                if (Convert.ToString(second).Length < 2)
                {
                    newSecond = "0" + Convert.ToString(second);
                }
                else
                {
                    newSecond = Convert.ToString(second);
                }
                return (newHour + ":" + newMinute + ":"
                        + newSecond);
            }
            catch (Exception)
            {
                return null;
            }
        }

求取2个时间的差值

   #region 获取时间差string GetTime(BsonString getTime)
        /// <summary>
        /// 获取时间差
        /// </summary>
        /// <param name="getTime">数据库时间</param>
        /// <returns>时间差</returns>
        private string GetTime(BsonString getTime)
        {
            var time1 = DateTime.ParseExact(Convert.ToString(getTime), "yyyy-MM-dd HH:mm:ss", null);
            var time = DateTime.Now - time1;

            if (time.TotalHours > 24)
            {
                return Math.Floor(time.TotalDays) + "天前";
            }
            if (time.TotalHours > 1)
            {
                return Math.Floor(time.TotalHours) + "小时前";
            }
            if (time.TotalMinutes > 1)
            {
                return Math.Floor(time.TotalMinutes) + "分钟前";
            }
            return Math.Floor(time.TotalSeconds) + "秒前";
        }
        #endregion
时间: 2024-10-02 05:23:59

将毫秒转化成时分秒的相关文章

C#实现毫秒转换成时分秒的方法

本文实例讲述了C#实现毫秒转换成时分秒的方法.分享给大家供大家参考.具体实现方法如下: public static String formatLongToTimeStr(Long l) { String str = ""; int hour = 0; int minute = 0; int second = 0; second = l.intValue() / 1000; if (second > 60) { minute = second / 60; second = seco

关于时间的操作(Java版)——将毫秒转换为年月日时分秒

第一种方式: import java.util.Calendar; import java.util.TimeZone; public class Test { /** * 将毫秒转换为年月日时分秒 * * @author GaoHuanjie */ public String getYearMonthDayHourMinuteSecond(long timeMillis) { Calendar calendar = Calendar.getInstance(TimeZone.getTimeZo

Oracle 把秒转成时分秒格式(呵呵4)

1 CREATE OR REPLACE FUNCTION to_time(sec IN NUMBER) RETURN VARCHAR2 IS 2 /*把秒转成时分秒格式 3 auth lzpong 201/09/16 4 */ 5 BEGIN 6 RETURN TRUNC(NVL(sec,0)/3600)||':'||SUBSTR(NUMTODSINTERVAL(NVL(sec,0), 'second'),15,5); 7 EXCEPTION WHEN OTHERS THEN RETURN '0

Oracle 把秒转成时分秒格式(hh24:mm:ss);检测字符串是否是数字

不说废话,贴代码: 1 CREATE OR REPLACE FUNCTION to_time(sec IN NUMBER) RETURN VARCHAR2 IS 2 /*把秒转成时分秒格式 3 auth lzpong 201/09/16 4 */ 5 BEGIN 6 RETURN TRUNC(NVL(sec,0)/3600)||':'||SUBSTR(NUMTODSINTERVAL(NVL(sec,0), 'second'),15,5); 7 EXCEPTION WHEN OTHERS THEN

PHP 将秒数转换成时分秒

将秒数转换成时分秒,PHP提供了一个函数gmstrftime,不过该函数仅限于24小时内的秒数转换.对于超过24小时的秒数,我们应该怎么让其显示出来呢,例如 34:02:02 $seconds = 3600*34+122; function changeTimeType($seconds){ if ($seconds>3600){ $hours = intval($seconds/3600); $time = $hours.":".gmstrftime('%M:%S', $sec

javascript把秒数转成时分秒显示

function transferTime(second) { if (Number(second) && second > 0) { second = parseInt(second) // 舍去秒数以后的小数位 } else { return '00:00:00' } // 计算时分秒 var h,m,s; s = second % 60 m = ((second - s) % 3600) / 60 h = parseInt(second / 3600) // 优化输出 func

毫秒数变成时分秒倒计时

js抽象代码: ;(function($){ /**时间间隔对象 * @author Karajan * @param gap 间隔毫秒 * @param {cT:当前时间(毫秒),eT:截止时间(毫秒),gap:间隔(毫秒),aEven:到点触发的事件function,iEven:初始化函数,初始化时被调用,lEven:倒计时结束触发方法} * */ function dateGap(gap){ var di=[],dCt=[1000*60*60*24,1000*60*60,1000*60,1

把秒数转换成时分秒

/** 转换时间格式 */ function changeTimeType($time) { if (is_numeric($time)) { $value = array( "days" => 0, "hours" => 0, "minutes" => 0, "seconds" => 0, ); if ($time >= 86400) { $value["days"] = f

JAVA将秒的总和转换成时分秒的格式

public static void main(String[] args) { String str = "221"; int seconds = Integer.parseInt(str); int temp=0; StringBuffer sb=new StringBuffer(); temp = seconds/3600; sb.append((temp<10)?"0"+temp+":":""+temp+&quo