Пример #1
0
        //# __________ PROTOCOL :: FORMAT __________ #//
        /**
         * I provide a very simple, and non-optimized, facility for formatting
         * dates in a variety of formats.  Valid format codes are:
         * {H}    : hour (1-12)
         * {HH}   : hour (01-12)
         * {H24}  : hour (0-23)
         * {HH24} : hour (00-23)
         * {M}    : minute (0-59)
         * {MM}   : minute (00-59)
         * {S}    : second (0-59)
         * {SS}   : second (00-59)
         * {MS}   : millisecond (000-999)
         * {am/pm}: am/pm (am, pm)
         */
        public static String Format(JwTime e, String format)
        {
            if ( e == null )
                return null;

            String s = format;
            s = JwUtility.ReplaceAll(s, "{H}",      e.GetHour12()+"");
            s = JwUtility.ReplaceAll(s, "{HH}",     Pad2(e.GetHour12()));
            s = JwUtility.ReplaceAll(s, "{H24}",    e.GetHour()+"");
            s = JwUtility.ReplaceAll(s, "{HH24}",   Pad2(e.GetHour()));

            s = JwUtility.ReplaceAll(s, "{M}",      e.GetMinute()+"");
            s = JwUtility.ReplaceAll(s, "{MM}",     Pad2(e.GetMinute()));

            s = JwUtility.ReplaceAll(s, "{S}",      e.GetSecond()+"");
            s = JwUtility.ReplaceAll(s, "{SS}",     Pad2(e.GetSecond()));

            s = JwUtility.ReplaceAll(s, "{MS}",     Pad3(e.GetMillisecond()));

            s = JwUtility.ReplaceAll(s, "{/p}",     e.IsAm() ? ""   : "p");
            s = JwUtility.ReplaceAll(s, "{/pm}",    e.IsAm() ? ""   : "pm");
            s = JwUtility.ReplaceAll(s, "{a/p}",    e.IsAm() ? "a"  : "p");
            s = JwUtility.ReplaceAll(s, "{A/P}",    e.IsAm() ? "A"  : "P");
            s = JwUtility.ReplaceAll(s, "{am/pm}",  e.IsAm() ? "am" : "pm");
            s = JwUtility.ReplaceAll(s, "{AM/PM}",  e.IsAm() ? "AM" : "PM");
            return s;
        }
Пример #2
0
        //# __________ PROTOCOL :: FORMAT __________ #//
        public static String Format_h_mm_am(JwTime t)
        {
            if ( t == null )
                return null;

            int hh = t.GetHour();
            int mm = t.GetMinute();
            String suffix = AM;
            if ( t.IsPm() )
            {
                hh -= 12;
                suffix = PM;
            }
            if ( hh == 0 ) hh = 12;
            return hh + COLON + Pad2(mm) + suffix;
        }
Пример #3
0
        public static String Format_h_mm_ss_msss_am(JwTime t)
        {
            if ( t == null )
                return null;

            int hh = t.GetHour();
            int mm = t.GetMinute();
            int ss = t.GetSecond();
            int ms = t.GetMillisecond();
            String suffix = AM;
            if ( t.IsPm() )
            {
                hh -= 12;
                suffix = PM;
            }
            if ( hh == 0 ) hh = 12;
            return hh + COLON + Pad2(mm) + COLON + Pad2(ss) + DOT + Pad3(ms) + suffix;
        }
Пример #4
0
        public static String Format_h_mm_ss_msss(JwTime t)
        {
            if ( t == null )
                return null;

            int hh = t.GetHour();
            int mm = t.GetMinute();
            int ss = t.GetSecond();
            int ms = t.GetMillisecond();
            return hh + COLON + Pad2(mm) + COLON + Pad2(ss) + DOT + Pad3(ms);
        }