美文网首页
Java 时间类 时间间隔类

Java 时间类 时间间隔类

作者: 29a45e70765e | 来源:发表于2016-11-20 22:34 被阅读167次

1. 开篇

哈哈,应谭同学的要求:

  • 时间间隔 = t

  • t < 20s ------ 刚刚

  • t > 20s & t < 1min ------ t 秒前

  • t > 1min & t < 1hour ------ t 分钟前

  • t > 1hour & t < 1day ------ t 小时前

  • t > 1day & t < 1month(受闰年影响) ------ t 天前

  • t > 1month & t < 1year ------ t 个月前

  • t > 1year & t < 1century ------ t 年前

  • t > 1century ------ t 个世纪前(ps:这个我自己加的)

于是写了个时间段转换的工具,为了效率和全部逻辑实现,遂重写了下UTC时间类。

2. 上代码

UTC 类


class UTC
{
    private static final int monthDaysTotalInterval[] = {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366, 397, 425, 456, 486, 517, 547, 578, 609, 639, 670, 700, 731, 762, 790, 821, 851, 882, 912, 943, 974, 1004, 1035, 1065, 1096, 1127, 1155, 1186, 1216, 1247, 1277, 1308, 1339, 1369, 1400, 1430, 1461, 1492, 1521, 1552, 1582, 1613, 1643, 1674, 1705, 1735, 1766, 1796, 1827, 1858, 1886, 1917, 1947, 1978, 2008, 2039, 2070, 2100, 2131, 2161, 2192, 2223, 2251, 2282, 2312, 2343, 2373, 2404, 2435, 2465, 2496, 2526, 2557, 2588, 2616, 2647, 2677, 2708, 2738, 2769, 2800, 2830, 2861, 2891, 2922, 2953, 2982, 3013, 3043, 3074, 3104, 3135, 3166, 3196, 3227, 3257, 3288, 3319, 3347, 3378, 3408, 3439, 3469, 3500, 3531, 3561, 3592, 3622, 3653, 3684, 3712, 3743, 3773, 3804, 3834, 3865, 3896, 3926, 3957, 3987, 4018, 4049, 4077, 4108, 4138, 4169, 4199, 4230, 4261, 4291, 4322, 4352, 4383, 4414, 4443, 4474, 4504, 4535, 4565, 4596, 4627, 4657, 4688, 4718, 4749, 4780, 4808, 4839, 4869, 4900, 4930, 4961, 4992, 5022, 5053, 5083, 5114, 5145, 5173, 5204, 5234, 5265, 5295, 5326, 5357, 5387, 5418, 5448, 5479, 5510, 5538, 5569, 5599, 5630, 5660, 5691, 5722, 5752, 5783, 5813, 5844, 5875, 5904, 5935, 5965, 5996, 6026, 6057, 6088, 6118, 6149, 6179, 6210, 6241, 6269, 6300, 6330, 6361, 6391, 6422, 6453, 6483, 6514, 6544, 6575, 6606, 6634, 6665, 6695, 6726, 6756, 6787, 6818, 6848, 6879, 6909, 6940, 6971, 6999, 7030, 7060, 7091, 7121, 7152, 7183, 7213, 7244, 7274, 7305, 7336, 7365, 7396, 7426, 7457, 7487, 7518, 7549, 7579, 7610, 7640, 7671, 7702, 7730, 7761, 7791, 7822, 7852, 7883, 7914, 7944, 7975, 8005, 8036, 8067, 8095, 8126, 8156, 8187, 8217, 8248, 8279, 8309, 8340, 8370, 8401, 8432, 8460, 8491, 8521, 8552, 8582, 8613, 8644, 8674, 8705, 8735, 8766, 8797, 8826, 8857, 8887, 8918, 8948, 8979, 9010, 9040, 9071, 9101, 9132, 9163, 9191, 9222, 9252, 9283, 9313, 9344, 9375, 9405, 9436, 9466, 9497, 9528, 9556, 9587, 9617, 9648, 9678, 9709, 9740, 9770, 9801, 9831, 9862, 9893, 9921, 9952, 9982, 10013, 10043, 10074, 10105, 10135, 10166, 10196, 10227, 10258, 10287, 10318, 10348, 10379, 10409, 10440, 10471, 10501, 10532, 10562, 10593, 10624, 10652, 10683, 10713, 10744, 10774, 10805, 10836, 10866, 10897, 10927, 10958, 10989, 11017, 11048, 11078, 11109, 11139, 11170, 11201, 11231, 11262, 11292, 11323, 11354, 11382, 11413, 11443, 11474, 11504, 11535, 11566, 11596, 11627, 11657, 11688, 11719, 11748, 11779, 11809, 11840, 11870, 11901, 11932, 11962, 11993, 12023, 12054, 12085, 12113, 12144, 12174, 12205, 12235, 12266, 12297, 12327, 12358, 12388, 12419, 12450, 12478, 12509, 12539, 12570, 12600, 12631, 12662, 12692, 12723, 12753, 12784, 12815, 12843, 12874, 12904, 12935, 12965, 12996, 13027, 13057, 13088, 13118, 13149, 13180, 13209, 13240, 13270, 13301, 13331, 13362, 13393, 13423, 13454, 13484, 13515, 13546, 13574, 13605, 13635, 13666, 13696, 13727, 13758, 13788, 13819, 13849, 13880, 13911, 13939, 13970, 14000, 14031, 14061, 14092, 14123, 14153, 14184, 14214, 14245, 14276, 14304, 14335, 14365, 14396, 14426, 14457, 14488, 14518, 14549, 14579, 14610, 14641, 14670, 14701, 14731, 14762, 14792, 14823, 14854, 14884, 14915, 14945, 14976, 15007, 15035, 15066, 15096, 15127, 15157, 15188, 15219, 15249, 15280, 15310, 15341, 15372, 15400, 15431, 15461, 15492, 15522, 15553, 15584, 15614, 15645, 15675, 15706, 15737, 15765, 15796, 15826, 15857, 15887, 15918, 15949, 15979, 16010, 16040, 16071, 16102, 16131, 16162, 16192, 16223, 16253, 16284, 16315, 16345, 16376, 16406, 16437, 16468, 16496, 16527, 16557, 16588, 16618, 16649, 16680, 16710, 16741, 16771, 16802, 16833, 16861, 16892, 16922, 16953, 16983, 17014, 17045, 17075, 17106, 17136, 17167, 17198, 17226, 17257, 17287, 17318, 17348, 17379, 17410, 17440, 17471, 17501, 17532, 17563, 17592, 17623, 17653, 17684, 17714, 17745, 17776, 17806, 17837, 17867, 17898, 17929, 17957, 17988, 18018, 18049, 18079, 18110, 18141, 18171, 18202, 18232, 18263, 18294, 18322, 18353, 18383, 18414, 18444, 18475, 18506, 18536, 18567, 18597, 18628, 18659, 18687, 18718, 18748, 18779, 18809, 18840, 18871, 18901, 18932, 18962, 18993, 19024, 19053, 19084, 19114, 19145, 19175, 19206, 19237, 19267, 19298, 19328, 19359, 19390, 19418, 19449, 19479, 19510, 19540, 19571, 19602, 19632, 19663, 19693, 19724, 19755, 19783, 19814, 19844, 19875, 19905, 19936, 19967, 19997, 20028, 20058, 20089, 20120, 20148, 20179, 20209, 20240, 20270, 20301, 20332, 20362, 20393, 20423, 20454, 20485, 20514, 20545, 20575, 20606, 20636, 20667, 20698, 20728, 20759, 20789, 20820, 20851, 20879, 20910, 20940, 20971, 21001, 21032, 21063, 21093, 21124, 21154, 21185, 21216, 21244, 21275, 21305, 21336, 21366, 21397, 21428, 21458, 21489, 21519, 21550, 21581, 21609, 21640, 21670, 21701, 21731, 21762, 21793, 21823, 21854, 21884, 21915, 21946, 21975, 22006, 22036, 22067, 22097, 22128, 22159, 22189, 22220, 22250, 22281, 22312, 22340, 22371, 22401, 22432, 22462, 22493, 22524, 22554, 22585, 22615, 22646, 22677, 22705, 22736, 22766, 22797, 22827, 22858, 22889, 22919, 22950, 22980, 23011, 23042, 23070, 23101, 23131, 23162, 23192, 23223, 23254, 23284, 23315, 23345, 23376, 23407, 23436, 23467, 23497, 23528, 23558, 23589, 23620, 23650, 23681, 23711, 23742, 23773, 23801, 23832, 23862, 23893, 23923, 23954, 23985, 24015, 24046, 24076, 24107, 24138, 24166, 24197, 24227, 24258, 24288, 24319, 24350, 24380, 24411, 24441, 24472, 24503, 24531, 24562, 24592, 24623, 24653, 24684, 24715, 24745, 24776, 24806, 24837, 24868, 24897, 24928, 24958, 24989, 25019, 25050, 25081, 25111, 25142, 25172, 25203, 25234, 25262, 25293, 25323, 25354, 25384, 25415, 25446, 25476, 25507, 25537, 25568, 25599, 25627, 25658, 25688, 25719, 25749, 25780, 25811, 25841, 25872, 25902, 25933, 25964, 25992, 26023, 26053, 26084, 26114, 26145, 26176, 26206, 26237, 26267, 26298, 26329, 26358, 26389, 26419, 26450, 26480, 26511, 26542, 26572, 26603, 26633, 26664, 26695, 26723, 26754, 26784, 26815, 26845, 26876, 26907, 26937, 26968, 26998, 27029, 27060, 27088, 27119, 27149, 27180, 27210, 27241, 27272, 27302, 27333, 27363, 27394, 27425, 27453, 27484, 27514, 27545, 27575, 27606, 27637, 27667, 27698, 27728, 27759, 27790, 27819, 27850, 27880, 27911, 27941, 27972, 28003, 28033, 28064, 28094, 28125, 28156, 28184, 28215, 28245, 28276, 28306, 28337, 28368, 28398, 28429, 28459, 28490, 28521, 28549, 28580, 28610, 28641, 28671, 28702, 28733, 28763, 28794, 28824, 28855, 28886, 28914, 28945, 28975, 29006, 29036, 29067, 29098, 29128, 29159, 29189, 29220, 29251, 29280, 29311, 29341, 29372, 29402, 29433, 29464, 29494, 29525, 29555, 29586, 29617, 29645, 29676, 29706, 29737, 29767, 29798, 29829, 29859, 29890, 29920, 29951, 29982, 30010, 30041, 30071, 30102, 30132, 30163, 30194, 30224, 30255, 30285, 30316, 30347, 30375, 30406, 30436, 30467, 30497, 30528, 30559, 30589, 30620, 30650, 30681, 30712, 30741, 30772, 30802, 30833, 30863, 30894, 30925, 30955, 30986, 31016, 31047, 31078, 31106, 31137, 31167, 31198, 31228, 31259, 31290, 31320, 31351, 31381, 31412, 31443, 31471, 31502, 31532, 31563, 31593, 31624, 31655, 31685, 31716, 31746, 31777, 31808, 31836, 31867, 31897, 31928, 31958, 31989, 32020, 32050, 32081, 32111, 32142, 32173, 32202, 32233, 32263, 32294, 32324, 32355, 32386, 32416, 32447, 32477, 32508, 32539, 32567, 32598, 32628, 32659, 32689, 32720, 32751, 32781, 32812, 32842, 32873, 32904, 32932, 32963, 32993, 33024, 33054, 33085, 33116, 33146, 33177, 33207, 33238, 33269, 33297, 33328, 33358, 33389, 33419, 33450, 33481, 33511, 33542, 33572, 33603, 33634, 33663, 33694, 33724, 33755, 33785, 33816, 33847, 33877, 33908, 33938, 33969, 34000, 34028, 34059, 34089, 34120, 34150, 34181, 34212, 34242, 34273, 34303, 34334, 34365, 34393, 34424, 34454, 34485, 34515, 34546, 34577, 34607, 34638, 34668, 34699, 34730, 34758, 34789, 34819, 34850, 34880, 34911, 34942, 34972, 35003, 35033, 35064, 35095, 35124, 35155, 35185, 35216, 35246, 35277, 35308, 35338, 35369, 35399, 35430, 35461, 35489, 35520, 35550, 35581, 35611, 35642, 35673, 35703, 35734, 35764, 35795, 35826, 35854, 35885, 35915, 35946, 35976, 36007, 36038, 36068, 36099, 36129, 36160, 36191, 36219, 36250, 36280, 36311, 36341, 36372, 36403, 36433, 36464, 36494, 36525, 36556, 36584, 36615, 36645, 36676, 36706, 36737, 36768, 36798, 36829, 36859, 36890, 36921, 36949, 36980, 37010, 37041, 37071, 37102, 37133, 37163, 37194, 37224, 37255, 37286, 37314, 37345, 37375, 37406, 37436, 37467, 37498, 37528, 37559, 37589, 37620, 37651, 37679, 37710, 37740, 37771, 37801, 37832, 37863, 37893, 37924, 37954, 37985, 38016, 38045, 38076, 38106, 38137, 38167, 38198, 38229, 38259, 38290, 38320, 38351, 38382, 38410, 38441, 38471, 38502, 38532, 38563, 38594, 38624, 38655, 38685, 38716, 38747, 38775, 38806, 38836, 38867, 38897, 38928, 38959, 38989, 39020, 39050, 39081, 39112, 39140, 39171, 39201, 39232, 39262, 39293, 39324, 39354, 39385, 39415, 39446, 39477, 39506, 39537, 39567, 39598, 39628, 39659, 39690, 39720, 39751, 39781, 39812, 39843, 39871, 39902, 39932, 39963, 39993, 40024, 40055, 40085, 40116, 40146, 40177, 40208, 40236, 40267, 40297, 40328, 40358, 40389, 40420, 40450, 40481, 40511, 40542, 40573, 40601, 40632, 40662, 40693, 40723, 40754, 40785, 40815, 40846, 40876, 40907, 40938, 40967, 40998, 41028, 41059, 41089, 41120, 41151, 41181, 41212, 41242, 41273, 41304, 41332, 41363, 41393, 41424, 41454, 41485, 41516, 41546, 41577, 41607, 41638, 41669, 41697, 41728, 41758, 41789, 41819, 41850, 41881, 41911, 41942, 41972, 42003, 42034, 42062, 42093, 42123, 42154, 42184, 42215, 42246, 42276, 42307, 42337, 42368, 42399, 42428, 42459, 42489, 42520, 42550, 42581, 42612, 42642, 42673, 42703, 42734, 42765, 42793, 42824, 42854, 42885, 42915, 42946, 42977, 43007, 43038, 43068, 43099, 43130, 43158, 43189, 43219, 43250, 43280, 43311, 43342, 43372, 43403, 43433, 43464, 43495, 43523, 43554, 43584, 43615, 43645, 43676, 43707, 43737, 43768, 43798, 43829, 43860, 43889, 43920, 43950, 43981, 44011, 44042, 44073, 44103, 44134, 44164, 44195, 44226, 44254, 44285, 44315, 44346, 44376, 44407, 44438, 44468, 44499, 44529, 44560, 44591, 44619, 44650, 44680, 44711, 44741, 44772, 44803, 44833, 44864, 44894, 44925, 44956, 44984, 45015, 45045, 45076, 45106, 45137, 45168, 45198, 45229, 45259, 45290, 45321, 45350, 45381, 45411, 45442, 45472, 45503, 45534, 45564, 45595, 45625, 45656, 45687, 45715, 45746, 45776, 45807, 45837, 45868, 45899, 45929, 45960, 45990, 46021, 46052, 46080, 46111, 46141, 46172, 46202, 46233, 46264, 46294, 46325, 46355, 46386, 46417, 46445, 46476, 46506, 46537, 46567, 46598, 46629, 46659, 46690, 46720, 46751, 46782, 46811, 46842, 46872, 46903, 46933, 46964, 46995, 47025, 47056, 47086, 47117, 47148, 47176, 47207, 47237, 47268, 47298, 47329, 47360, 47390, 47421, 47451, 47482, 47513, 47541, 47572, 47602, 47633, 47663, 47694, 47725, 47755, 47786, 47816, 47847, 47878, 47906, 47937, 47967, 47998, 48028, 48059, 48090, 48120, 48151, 48181, 48212, 48243, 48272, 48303, 48333, 48364, 48394, 48425, 48456, 48486, 48517, 48547, 48578, 48609, 48637, 48668, 48698, 48729, 48759, 48790, 48821, 48851, 48882, 48912, 48943, 48974, 49002, 49033, 49063, 49094, 49124, 49155, 49186, 49216, 49247, 49277, 49308, 49339, 49367, 49398, 49428, 49459, 49489, 49520, 49551, 49581, 49612, 49642, 49673, 49704, 49733, 49764, 49794, 49825, 49855, 49886, 49917, 49947, 49978, 50008, 50039, 50070, 50098, 50129, 50159, 50190, 50220, 50251, 50282, 50312, 50343, 50373, 50404, 50435, 50463, 50494, 50524, 50555, 50585, 50616, 50647, 50677, 50708, 50738, 50769, 50800, 50828, 50859, 50889, 50920, 50950, 50981, 51012, 51042, 51073, 51103, 51134, 51165, 51194, 51225, 51255, 51286, 51316, 51347, 51378, 51408, 51439, 51469, 51500, 51531, 51559, 51590, 51620, 51651, 51681, 51712, 51743, 51773, 51804, 51834, 51865, 51896, 51924, 51955, 51985, 52016, 52046, 52077, 52108, 52138, 52169, 52199, 52230, 52261, 52289, 52320, 52350, 52381, 52411, 52442, 52473, 52503, 52534, 52564, 52595, 52626, 52655, 52686, 52716, 52747, 52777, 52808, 52839, 52869, 52900, 52930, 52961, 52992, 53020, 53051, 53081, 53112, 53142, 53173, 53204, 53234, 53265, 53295, 53326, 53357, 53385, 53416, 53446, 53477, 53507, 53538, 53569, 53599, 53630, 53660, 53691, 53722, 53750, 53781, 53811, 53842, 53872, 53903, 53934, 53964, 53995, 54025, 54056, 54087, 54116, 54147, 54177, 54208, 54238, 54269, 54300, 54330, 54361, 54391, 54422, 54453, 54481, 54512, 54542, 54573, 54603, 54634, 54665, 54695, 54726, 54756, 54787, 54818, 54846, 54877, 54907, 54938, 54968, 54999, 55030, 55060, 55091, 55121, 55152, 55183, 55211, 55242, 55272, 55303, 55333, 55364, 55395, 55425, 55456, 55486, 55517, 55548, 55577, 55608, 55638, 55669, 55699, 55730, 55761, 55791, 55822, 55852, 55883, 55914, 55942, 55973, 56003, 56034, 56064, 56095, 56126, 56156, 56187, 56217, 56248, 56279, 56307, 56338, 56368, 56399, 56429, 56460, 56491, 56521, 56552, 56582, 56613, 56644, 56672, 56703, 56733, 56764, 56794, 56825, 56856, 56886, 56917, 56947, 56978, 57009, 57038, 57069, 57099, 57130, 57160, 57191, 57222, 57252, 57283, 57313, 57344, 57375, 57403, 57434, 57464, 57495, 57525, 57556, 57587, 57617, 57648, 57678, 57709, 57740, 57768, 57799, 57829, 57860, 57890, 57921, 57952, 57982, 58013, 58043, 58074, 58105, 58133, 58164, 58194, 58225, 58255, 58286, 58317, 58347, 58378, 58408, 58439, 58470, 58499, 58530, 58560, 58591, 58621, 58652, 58683, 58713, 58744, 58774, 58805, 58836, 58864, 58895, 58925, 58956, 58986, 59017, 59048, 59078, 59109, 59139, 59170, 59201, 59229, 59260, 59290, 59321, 59351, 59382, 59413, 59443, 59474, 59504, 59535, 59566, 59594, 59625, 59655, 59686, 59716, 59747, 59778, 59808, 59839, 59869, 59900, 59931, 59960, 59991, 60021, 60052, 60082, 60113, 60144, 60174, 60205, 60235, 60266, 60297, 60325, 60356, 60386, 60417, 60447, 60478, 60509, 60539, 60570, 60600, 60631, 60662, 60690, 60721, 60751, 60782, 60812, 60843, 60874, 60904, 60935, 60965, 60996, 61027, 61055, 61086, 61116, 61147, 61177, 61208, 61239, 61269, 61300, 61330, 61361, 61392, 61421, 61452, 61482, 61513, 61543, 61574, 61605, 61635, 61666, 61696, 61727, 61758, 61786, 61817, 61847, 61878, 61908, 61939, 61970, 62000, 62031, 62061, 62092, 62123, 62151, 62182, 62212, 62243, 62273, 62304, 62335, 62365, 62396, 62426, 62457, 62488, 62516, 62547, 62577, 62608, 62638, 62669, 62700, 62730, 62761, 62791, 62822, 62853, 62882, 62913, 62943, 62974, 63004, 63035, 63066, 63096, 63127, 63157, 63188, 63219, 63247, 63278, 63308, 63339, 63369, 63400, 63431, 63461, 63492, 63522, 63553, 63584, 63612, 63643, 63673, 63704, 63734, 63765, 63796, 63826, 63857, 63887, 63918, 63949, 63977, 64008, 64038, 64069, 64099, 64130, 64161, 64191, 64222, 64252, 64283, 64314, 64343, 64374, 64404, 64435, 64465, 64496, 64527, 64557, 64588, 64618, 64649, 64680, 64708, 64739, 64769, 64800, 64830, 64861, 64892, 64922, 64953, 64983, 65014, 65045, 65073, 65104, 65134, 65165, 65195, 65226, 65257, 65287, 65318, 65348, 65379, 65410, 65438, 65469, 65499, 65530, 65560, 65591, 65622, 65652, 65683, 65713, 65744, 65775, 65804, 65835, 65865, 65896, 65926, 65957, 65988, 66018, 66049, 66079, 66110, 66141, 66169, 66200, 66230, 66261, 66291, 66322, 66353, 66383, 66414, 66444, 66475, 66506, 66534, 66565, 66595, 66626, 66656, 66687, 66718, 66748, 66779, 66809, 66840, 66871, 66899, 66930, 66960, 66991, 67021, 67052, 67083, 67113, 67144, 67174, 67205, 67236, 67265, 67296, 67326, 67357, 67387, 67418, 67449, 67479, 67510, 67540, 67571, 67602, 67630, 67661, 67691, 67722, 67752, 67783, 67814, 67844, 67875, 67905, 67936, 67967, 67995, 68026, 68056, 68087, 68117, 68148, 68179, 68209, 68240, 68270, 68301, 68332, 68360, 68391, 68421, 68452, 68482, 68513, 68544, 68574, 68605, 68635, 68666, 68697, 68726, 68757, 68787, 68818, 68848, 68879, 68910, 68940, 68971, 69001, 69032, 69063, 69091, 69122, 69152, 69183, 69213, 69244, 69275, 69305, 69336, 69366, 69397, 69428, 69456, 69487, 69517, 69548, 69578, 69609, 69640, 69670, 69701, 69731, 69762, 69793, 69821, 69852, 69882, 69913, 69943, 69974, 70005, 70035, 70066, 70096, 70127, 70158, 70187, 70218, 70248, 70279, 70309, 70340, 70371, 70401, 70432, 70462, 70493, 70524, 70552, 70583, 70613, 70644, 70674, 70705, 70736, 70766, 70797, 70827, 70858, 70889, 70917, 70948, 70978, 71009, 71039, 71070, 71101, 71131, 71162, 71192, 71223, 71254, 71282, 71313, 71343, 71374, 71404, 71435, 71466, 71496, 71527, 71557, 71588, 71619, 71648, 71679, 71709, 71740, 71770, 71801, 71832, 71862, 71893, 71923, 71954, 71985, 72013, 72044, 72074, 72105, 72135, 72166, 72197, 72227, 72258, 72288, 72319, 72350, 72378, 72409, 72439, 72470, 72500, 72531, 72562, 72592, 72623, 72653, 72684, 72715, 72743, 72774, 72804, 72835, 72865, 72896, 72927, 72957, 72988, 73018, 73049, 73080, 73108, 73139, 73169, 73200, 73230, 73261, 73292, 73322, 73353, 73383, 73414, 73445, 73473, 73504, 73534, 73565, 73595, 73626, 73657, 73687, 73718, 73748, 73779, 73810, 73838, 73869, 73899, 73930, 73960, 73991, 74022, 74052, 74083, 74113, 74144, 74175, 74203, 74234, 74264, 74295, 74325, 74356, 74387, 74417, 74448, 74478, 74509, 74540, 74569, 74600, 74630, 74661, 74691, 74722, 74753, 74783, 74814, 74844, 74875, 74906, 74934, 74965, 74995, 75026, 75056, 75087, 75118, 75148, 75179, 75209, 75240, 75271, 75299, 75330, 75360, 75391, 75421, 75452, 75483, 75513, 75544, 75574, 75605, 75636, 75664, 75695, 75725, 75756, 75786, 75817, 75848, 75878, 75909, 75939, 75970, 76001, 76030, 76061, 76091, 76122, 76152, 76183, 76214, 76244, 76275, 76305, 76336, 76367, 76395, 76426, 76456, 76487, 76517, 76548, 76579, 76609, 76640, 76670, 76701, 76732, 76760, 76791, 76821, 76852, 76882, 76913, 76944, 76974, 77005, 77035, 77066, 77097, 77125, 77156, 77186, 77217, 77247, 77278, 77309, 77339, 77370, 77400, 77431, 77462, 77491, 77522, 77552, 77583, 77613, 77644, 77675, 77705, 77736, 77766, 77797, 77828, 77856, 77887, 77917, 77948, 77978, 78009, 78040, 78070, 78101, 78131, 78162, 78193, 78221, 78252, 78282, 78313, 78343, 78374, 78405, 78435, 78466, 78496, 78527, 78558, 78586, 78617, 78647, 78678, 78708, 78739, 78770, 78800, 78831, 78861, 78892, 78923, 78952, 78983, 79013, 79044, 79074, 79105, 79136, 79166, 79197, 79227, 79258, 79289, 79317, 79348, 79378, 79409, 79439, 79470, 79501, 79531, 79562, 79592, 79623, 79654, 79682, 79713, 79743, 79774, 79804, 79835, 79866, 79896, 79927, 79957, 79988, 80019, 80047, 80078, 80108, 80139, 80169, 80200, 80231, 80261, 80292, 80322, 80353, 80384, 80413, 80444, 80474, 80505, 80535, 80566, 80597, 80627, 80658, 80688, 80719, 80750, 80778, 80809, 80839, 80870, 80900, 80931, 80962, 80992, 81023, 81053, 81084, 81115, 81143, 81174, 81204, 81235, 81265, 81296, 81327, 81357, 81388, 81418, 81449, 81480, 81508, 81539, 81569, 81600, 81630, 81661, 81692, 81722, 81753, 81783, 81814, 81845, 81874, 81905, 81935, 81966, 81996, 82027, 82058, 82088, 82119, 82149, 82180, 82211, 82239, 82270, 82300, 82331, 82361, 82392, 82423, 82453, 82484, 82514, 82545, 82576, 82604, 82635, 82665, 82696, 82726, 82757, 82788, 82818, 82849, 82879, 82910, 82941, 82969, 83000, 83030, 83061, 83091, 83122, 83153, 83183, 83214, 83244, 83275, 83306, 83335, 83366, 83396, 83427, 83457, 83488, 83519, 83549, 83580, 83610, 83641, 83672, 83700, 83731, 83761, 83792, 83822, 83853, 83884, 83914, 83945, 83975, 84006, 84037, 84065, 84096, 84126, 84157, 84187, 84218, 84249, 84279, 84310, 84340, 84371, 84402, 84430, 84461, 84491, 84522, 84552, 84583, 84614, 84644, 84675, 84705, 84736, 84767, 84796, 84827, 84857, 84888, 84918, 84949, 84980, 85010, 85041, 85071, 85102, 85133, 85161, 85192, 85222, 85253, 85283, 85314, 85345, 85375, 85406, 85436, 85467, 85498, 85526, 85557, 85587, 85618, 85648, 85679, 85710, 85740, 85771, 85801, 85832, 85863, 85891, 85922, 85952, 85983, 86013, 86044, 86075, 86105, 86136, 86166, 86197, 86228, 86257, 86288, 86318, 86349, 86379, 86410, 86441, 86471, 86502, 86532, 86563, 86594, 86622, 86653, 86683, 86714, 86744, 86775, 86806, 86836, 86867, 86897, 86928, 86959, 86987, 87018, 87048, 87079, 87109, 87140, 87171, 87201, 87232, 87262, 87293, 87324, 87352, 87383, 87413, 87444, 87474, 87505, 87536, 87566, 87597, 87627, 87658, 87689, 87718, 87749, 87779, 87810, 87840, 87871, 87902, 87932, 87963, 87993, 88024, 88055, 88083, 88114, 88144, 88175, 88205, 88236, 88267, 88297, 88328, 88358, 88389, 88420, 88448, 88479, 88509, 88540, 88570, 88601, 88632, 88662, 88693, 88723, 88754, 88785, 88813, 88844, 88874, 88905, 88935, 88966, 88997, 89027, 89058, 89088, 89119, 89150, 89179, 89210, 89240, 89271, 89301, 89332, 89363, 89393, 89424, 89454, 89485, 89516, 89544, 89575, 89605, 89636, 89666, 89697, 89728, 89758, 89789, 89819, 89850, 89881, 89909, 89940, 89970, 90001, 90031, 90062, 90093, 90123, 90154, 90184, 90215, 90246, 90274, 90305, 90335, 90366, 90396, 90427, 90458, 90488, 90519, 90549, 90580, 90611, 90640, 90671, 90701, 90732, 90762, 90793, 90824, 90854, 90885, 90915, 90946, 90977, 91005, 91036, 91066, 91097, 91127, 91158, 91189, 91219, 91250, 91280, 91311, 91342, 91370, 91401, 91431, 91462, 91492, 91523, 91554, 91584, 91615, 91645, 91676, 91707, 91735, 91766, 91796, 91827, 91857, 91888, 91919, 91949, 91980, 92010, 92041, 92072, 92101, 92132, 92162, 92193, 92223, 92254, 92285, 92315, 92346, 92376, 92407, 92438, 92466, 92497, 92527, 92558, 92588, 92619, 92650, 92680, 92711, 92741, 92772, 92803, 92831, 92862, 92892, 92923, 92953, 92984, 93015, 93045, 93076, 93106, 93137, 93168, 93196, 93227, 93257, 93288, 93318, 93349, 93380, 93410, 93441, 93471, 93502, 93533, 93562, 93593, 93623, 93654, 93684, 93715, 93746, 93776, 93807, 93837, 93868, 93899, 93927, 93958, 93988, 94019, 94049, 94080, 94111, 94141, 94172, 94202, 94233, 94264, 94292, 94323, 94353, 94384, 94414, 94445, 94476, 94506, 94537, 94567, 94598, 94629, 94657, 94688, 94718, 94749, 94779, 94810, 94841, 94871, 94902, 94932, 94963, 94994, 95023, 95054, 95084, 95115, 95145, 95176, 95207, 95237, 95268, 95298, 95329, 95360, 95388, 95419, 95449, 95480, 95510, 95541, 95572, 95602, 95633, 95663, 95694, 95725, 95753, 95784, 95814, 95845, 95875, 95906, 95937, 95967, 95998, 96028, 96059, 96090, 96118, 96149, 96179, 96210, 96240, 96271, 96302, 96332, 96363, 96393, 96424, 96455, 96484, 96515, 96545, 96576, 96606, 96637, 96668, 96698, 96729, 96759, 96790, 96821, 96849, 96880, 96910, 96941, 96971, 97002, 97033, 97063, 97094, 97124, 97155, 97186, 97214, 97245, 97275, 97306, 97336, 97367, 97398, 97428, 97459, 97489, 97520, 97551, 97579, 97610, 97640, 97671, 97701, 97732, 97763, 97793, 97824, 97854, 97885, 97916, 97945, 97976, 98006, 98037, 98067, 98098, 98129, 98159, 98190, 98220, 98251, 98282, 98310, 98341, 98371, 98402, 98432, 98463, 98494, 98524, 98555, 98585, 98616, 98647, 98675, 98706, 98736, 98767, 98797, 98828, 98859, 98889, 98920, 98950, 98981, 99012, 99040, 99071, 99101, 99132, 99162, 99193, 99224, 99254, 99285, 99315, 99346, 99377, 99406, 99437, 99467, 99498, 99528, 99559, 99590, 99620, 99651, 99681, 99712, 99743, 99771, 99802, 99832, 99863, 99893, 99924, 99955, 99985, 100016, 100046, 100077, 100108, 100136, 100167, 100197, 100228, 100258, 100289, 100320, 100350, 100381, 100411, 100442, 100473, 100501, 100532, 100562, 100593, 100623, 100654, 100685, 100715, 100746, 100776, 100807, 100838, 100867, 100898, 100928, 100959, 100989, 101020, 101051, 101081, 101112, 101142, 101173, 101204, 101232, 101263, 101293, 101324, 101354, 101385, 101416, 101446, 101477, 101507, 101538, 101569, 101597, 101628, 101658, 101689, 101719, 101750, 101781, 101811, 101842, 101872, 101903, 101934, 101962, 101993, 102023, 102054, 102084, 102115, 102146, 102176, 102207, 102237, 102268, 102299, 102328, 102359, 102389, 102420, 102450, 102481, 102512, 102542, 102573, 102603, 102634, 102665, 102693, 102724, 102754, 102785, 102815, 102846, 102877, 102907, 102938, 102968, 102999, 103030, 103058, 103089, 103119, 103150, 103180, 103211, 103242, 103272, 103303, 103333, 103364, 103395, 103423, 103454, 103484, 103515, 103545, 103576, 103607, 103637, 103668, 103698, 103729, 103760, 103789, 103820, 103850, 103881, 103911, 103942, 103973, 104003, 104034, 104064, 104095, 104126, 104154, 104185, 104215, 104246, 104276, 104307, 104338, 104368, 104399, 104429, 104460, 104491, 104519, 104550, 104580, 104611, 104641, 104672, 104703, 104733, 104764, 104794, 104825, 104856, 104884, 104915, 104945, 104976, 105006, 105037, 105068, 105098, 105129, 105159, 105190, 105221, 105250, 105281, 105311, 105342, 105372, 105403, 105434, 105464, 105495, 105525, 105556, 105587, 105615, 105646, 105676, 105707, 105737, 105768, 105799, 105829, 105860, 105890, 105921, 105952, 105980, 106011, 106041, 106072, 106102, 106133, 106164, 106194, 106225, 106255, 106286, 106317, 106345, 106376, 106406, 106437, 106467, 106498, 106529, 106559, 106590, 106620, 106651, 106682, 106711, 106742, 106772, 106803, 106833, 106864, 106895, 106925, 106956, 106986, 107017, 107048, 107076, 107107, 107137, 107168, 107198, 107229, 107260, 107290, 107321, 107351, 107382, 107413, 107441, 107472, 107502, 107533, 107563, 107594, 107625, 107655, 107686, 107716, 107747, 107778, 107806, 107837, 107867, 107898, 107928, 107959, 107990, 108020, 108051, 108081, 108112, 108143, 108172, 108203, 108233, 108264, 108294, 108325, 108356, 108386, 108417, 108447, 108478, 108509, 108537, 108568, 108598, 108629, 108659, 108690, 108721, 108751, 108782, 108812, 108843, 108874, 108902, 108933, 108963, 108994, 109024, 109055, 109086, 109116, 109147, 109177, 109208, 109239, 109267, 109298, 109328, 109359, 109389, 109420, 109451, 109481, 109512, 109542, 109573, 109604, 109632, 109663, 109693, 109724, 109754, 109785, 109816, 109846, 109877, 109907, 109938, 109969, 109997, 110028, 110058, 110089, 110119, 110150, 110181, 110211, 110242, 110272, 110303, 110334, 110362, 110393, 110423, 110454, 110484, 110515, 110546, 110576, 110607, 110637, 110668, 110699, 110727, 110758, 110788, 110819, 110849, 110880, 110911, 110941, 110972, 111002, 111033, 111064, 111093, 111124, 111154, 111185, 111215, 111246, 111277, 111307, 111338, 111368, 111399, 111430, 111458, 111489, 111519, 111550, 111580, 111611, 111642, 111672, 111703, 111733, 111764, 111795, 111823, 111854, 111884, 111915, 111945, 111976, 112007, 112037, 112068, 112098, 112129, 112160, 112188, 112219, 112249, 112280, 112310, 112341, 112372, 112402, 112433, 112463, 112494, 112525, 112554, 112585, 112615, 112646, 112676, 112707, 112738, 112768, 112799, 112829, 112860, 112891, 112919, 112950, 112980, 113011, 113041, 113072, 113103, 113133, 113164, 113194, 113225, 113256, 113284, 113315, 113345, 113376, 113406, 113437, 113468, 113498, 113529, 113559, 113590, 113621, 113649, 113680, 113710, 113741, 113771, 113802, 113833, 113863, 113894, 113924, 113955, 113986, 114015, 114046, 114076, 114107, 114137, 114168, 114199, 114229, 114260, 114290, 114321, 114352, 114380, 114411, 114441, 114472, 114502, 114533, 114564, 114594, 114625, 114655, 114686, 114717, 114745, 114776, 114806, 114837, 114867, 114898, 114929, 114959, 114990, 115020, 115051, 115082, 115110, 115141, 115171, 115202, 115232, 115263, 115294, 115324, 115355, 115385, 115416, 115447, 115476, 115507, 115537, 115568, 115598, 115629, 115660, 115690, 115721, 115751, 115782, 115813, 115841, 115872, 115902, 115933, 115963, 115994, 116025, 116055, 116086, 116116, 116147, 116178, 116206, 116237, 116267, 116298, 116328, 116359, 116390, 116420, 116451, 116481, 116512, 116543, 116571, 116602, 116632, 116663, 116693, 116724, 116755, 116785, 116816, 116846, 116877, 116908, 116937, 116968, 116998, 117029, 117059, 117090, 117121, 117151, 117182, 117212, 117243, 117274, 117302, 117333, 117363, 117394, 117424, 117455, 117486, 117516, 117547, 117577, 117608, 117639, 117667, 117698, 117728, 117759, 117789, 117820, 117851, 117881, 117912, 117942, 117973, 118004, 118032, 118063, 118093, 118124, 118154, 118185, 118216, 118246, 118277, 118307, 118338, 118369, 118398, 118429, 118459, 118490, 118520, 118551, 118582, 118612, 118643, 118673, 118704, 118735, 118763, 118794, 118824, 118855, 118885, 118916, 118947, 118977, 119008, 119038, 119069, 119100, 119128, 119159, 119189, 119220, 119250, 119281, 119312, 119342, 119373, 119403, 119434, 119465, 119493, 119524, 119554, 119585, 119615, 119646, 119677, 119707, 119738, 119768, 119799, 119830, 119859, 119890, 119920, 119951, 119981, 120012, 120043, 120073, 120104, 120134, 120165, 120196, 120224, 120255, 120285, 120316, 120346, 120377, 120408, 120438, 120469, 120499, 120530, 120561, 120589, 120620, 120650, 120681, 120711, 120742, 120773, 120803, 120834, 120864, 120895, 120926, 120954, 120985, 121015, 121046, 121076, 121107, 121138, 121168, 121199, 121229, 121260, 121291, 121320, 121351, 121381, 121412, 121442, 121473, 121504, 121534, 121565, 121595, 121626, 121657, 121685, 121716, 121746, 121777, 121807, 121838, 121869, 121899, 121930, 121960, 121991, 122022, 122050, 122081, 122111, 122142, 122172, 122203, 122234, 122264, 122295, 122325, 122356, 122387, 122415, 122446, 122476, 122507, 122537, 122568, 122599, 122629, 122660, 122690, 122721, 122752, 122781, 122812, 122842, 122873, 122903, 122934, 122965, 122995, 123026, 123056, 123087, 123118, 123146, 123177, 123207, 123238, 123268, 123299, 123330, 123360, 123391, 123421, 123452, 123483, 123511, 123542, 123572, 123603, 123633, 123664, 123695, 123725, 123756, 123786, 123817, 123848, 123876, 123907, 123937, 123968, 123998, 124029, 124060, 124090, 124121, 124151, 124182, 124213, 124242, 124273, 124303, 124334, 124364, 124395, 124426, 124456, 124487, 124517, 124548, 124579, 124607, 124638, 124668, 124699, 124729, 124760, 124791, 124821, 124852, 124882, 124913, 124944, 124972, 125003, 125033, 125064, 125094, 125125, 125156, 125186, 125217, 125247, 125278, 125309, 125337, 125368, 125398, 125429, 125459, 125490, 125521, 125551, 125582, 125612, 125643, 125674, 125703, 125734, 125764, 125795, 125825, 125856, 125887, 125917, 125948, 125978, 126009, 126040, 126068, 126099, 126129, 126160, 126190, 126221, 126252, 126282, 126313, 126343, 126374, 126405, 126433, 126464, 126494, 126525, 126555, 126586, 126617, 126647, 126678, 126708, 126739, 126770, 126798, 126829, 126859, 126890, 126920, 126951, 126982, 127012, 127043, 127073, 127104, 127135, 127164, 127195, 127225, 127256, 127286, 127317, 127348, 127378, 127409, 127439, 127470, 127501, 127529, 127560, 127590, 127621, 127651, 127682, 127713, 127743, 127774, 127804, 127835, 127866, 127894, 127925, 127955, 127986, 128016, 128047, 128078, 128108, 128139, 128169, 128200, 128231, 128259, 128290, 128320, 128351, 128381, 128412, 128443, 128473, 128504, 128534, 128565, 128596, 128625, 128656, 128686, 128717, 128747, 128778, 128809, 128839, 128870, 128900, 128931, 128962, 128990, 129021, 129051, 129082, 129112, 129143, 129174, 129204, 129235, 129265, 129296, 129327, 129355, 129386, 129416, 129447, 129477, 129508, 129539, 129569, 129600, 129630, 129661, 129692, 129720, 129751, 129781, 129812, 129842, 129873, 129904, 129934, 129965, 129995, 130026, 130057, 130086, 130117, 130147, 130178, 130208, 130239, 130270, 130300, 130331, 130361, 130392, 130423, 130451, 130482, 130512, 130543, 130573, 130604, 130635, 130665, 130696, 130726, 130757, 130788, 130816, 130847, 130877, 130908, 130938, 130969, 131000, 131030, 131061, 131091, 131122, 131153, 131181, 131212, 131242, 131273, 131303, 131334, 131365, 131395, 131426, 131456, 131487, 131518, 131547, 131578, 131608, 131639, 131669, 131700, 131731, 131761, 131792, 131822, 131853, 131884, 131912, 131943, 131973, 132004, 132034, 132065, 132096, 132126, 132157, 132187, 132218, 132249, 132277, 132308, 132338, 132369, 132399, 132430, 132461, 132491, 132522, 132552, 132583, 132614, 132642, 132673, 132703, 132734, 132764, 132795, 132826, 132856, 132887, 132917, 132948, 132979, 133008, 133039, 133069, 133100, 133130, 133161, 133192, 133222, 133253, 133283, 133314, 133345, 133373, 133404, 133434, 133465, 133495, 133526, 133557, 133587, 133618, 133648, 133679, 133710, 133738, 133769, 133799, 133830, 133860, 133891, 133922, 133952, 133983, 134013, 134044, 134075, 134103, 134134, 134164, 134195, 134225, 134256, 134287, 134317, 134348, 134378, 134409, 134440, 134469, 134500, 134530, 134561, 134591, 134622, 134653, 134683, 134714, 134744, 134775, 134806, 134834, 134865, 134895, 134926, 134956, 134987, 135018, 135048, 135079, 135109, 135140, 135171, 135199, 135230, 135260, 135291, 135321, 135352, 135383, 135413, 135444, 135474, 135505, 135536, 135564, 135595, 135625, 135656, 135686, 135717, 135748, 135778, 135809, 135839, 135870, 135901, 135930, 135961, 135991, 136022, 136052, 136083, 136114, 136144, 136175, 136205, 136236, 136267, 136295, 136326, 136356, 136387, 136417, 136448, 136479, 136509, 136540, 136570, 136601, 136632, 136660, 136691, 136721, 136752, 136782, 136813, 136844, 136874, 136905, 136935, 136966, 136997, 137025, 137056, 137086, 137117, 137147, 137178, 137209, 137239, 137270, 137300, 137331, 137362, 137391, 137422, 137452, 137483, 137513, 137544, 137575, 137605, 137636, 137666, 137697, 137728, 137756, 137787, 137817, 137848, 137878, 137909, 137940, 137970, 138001, 138031, 138062, 138093, 138121, 138152, 138182, 138213, 138243, 138274, 138305, 138335, 138366, 138396, 138427, 138458, 138486, 138517, 138547, 138578, 138608, 138639, 138670, 138700, 138731, 138761, 138792, 138823, 138852, 138883, 138913, 138944, 138974, 139005, 139036, 139066, 139097, 139127, 139158, 139189, 139217, 139248, 139278, 139309, 139339, 139370, 139401, 139431, 139462, 139492, 139523, 139554, 139582, 139613, 139643, 139674, 139704, 139735, 139766, 139796, 139827, 139857, 139888, 139919, 139947, 139978, 140008, 140039, 140069, 140100, 140131, 140161, 140192, 140222, 140253, 140284, 140313, 140344, 140374, 140405, 140435, 140466, 140497, 140527, 140558, 140588, 140619, 140650, 140678, 140709, 140739, 140770, 140800, 140831, 140862, 140892, 140923, 140953, 140984, 141015, 141043, 141074, 141104, 141135, 141165, 141196, 141227, 141257, 141288, 141318, 141349, 141380, 141408, 141439, 141469, 141500, 141530, 141561, 141592, 141622, 141653, 141683, 141714, 141745, 141774, 141805, 141835, 141866, 141896, 141927, 141958, 141988, 142019, 142049, 142080, 142111, 142139, 142170, 142200, 142231, 142261, 142292, 142323, 142353, 142384, 142414, 142445, 142476, 142504, 142535, 142565, 142596, 142626, 142657, 142688, 142718, 142749, 142779, 142810, 142841, 142869, 142900, 142930, 142961, 142991, 143022, 143053, 143083, 143114, 143144, 143175, 143206, 143235, 143266, 143296, 143327, 143357, 143388, 143419, 143449, 143480, 143510, 143541, 143572, 143600, 143631, 143661, 143692, 143722, 143753, 143784, 143814, 143845, 143875, 143906, 143937, 143965, 143996, 144026, 144057, 144087, 144118, 144149, 144179, 144210, 144240, 144271, 144302, 144330, 144361, 144391, 144422, 144452, 144483, 144514, 144544, 144575, 144605, 144636, 144667, 144696, 144727, 144757, 144788, 144818, 144849, 144880, 144910, 144941, 144971, 145002, 145033, 145061, 145092, 145122, 145153, 145183, 145214, 145245, 145275, 145306, 145336, 145367, 145398, 145426, 145457, 145487, 145518, 145548, 145579, 145610, 145640, 145671, 145701, 145732, 145763, 145791, 145822, 145852, 145883, 145913, 145944, 145975, 146005, 146036, 146066, 146097};
    public static final UTC TIMESTAMP_ZERO = new UTC(1970, 1, 1, 0, 0, 0, 0);
    public static final int[] normalMonthDays = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    public static final int[] leapMonthDays = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

    private int year;
    private int month;
    private int day;
    private int hour;
    private int minute;
    private int second;
    private int millisecond;


    public UTC(long timestamp)
    {
        this.copyFrom(TIMESTAMP_ZERO).add(timestamp);
    }

    public UTC(int year, int month, int day, int hour, int minute, int second, int millisecond)
    {
        this.year = year;
        this.month = month;
        this.day = day;
        this.hour = hour;
        this.minute = minute;
        this.second = second;
        this.millisecond = millisecond;
    }

    public UTCSpan subtract(UTC a)
    {
        return new UTCSpan(a, this);
    }

    private int div2Find(int[] array, int value, int from, int to)
    {
        if (from + 1 >= to)
            return from;

        int mid = (from + to) / 2;
        if (array[mid] > value)
            return div2Find(array, value, from, mid);
        else
            return div2Find(array, value, mid, to);
    }

    public void add(long milliseconds)
    {
        long adds = milliseconds;
        int carry = 0;

        // millisecond
        millisecond += adds % 1000;
        if (millisecond >= 1000)
        {
            millisecond -= 1000;
            carry = 1;
        }
        else
            carry = 0;
        adds /= 1000;

        // second
        second += adds % 60 + carry;
        if (second >= 60)
        {
            second -= 60;
            carry = 1;
        }
        else
            carry = 0;
        adds /= 60;

        // minute
        minute += adds % 60 + carry;
        if (minute >= 60)
        {
            minute -= 60;
            carry = 1;
        }
        else
            carry = 0;
        adds /= 60;

        // hour
        hour += adds % 24 + carry;
        if (hour >= 24)
        {
            minute -= 24;
            carry = 1;
        }
        else
            carry = 0;
        adds /= 24;

        // day & month & year maybe you can not understand this , follow this:
        int mstart = (year % 400) * 12 + month - 1;
        adds += monthDaysTotalInterval[mstart] + day - 1;
        int m400Incr = year / 400 + (int) adds / 146097;
        adds %= 146097;
        int mindex = div2Find(monthDaysTotalInterval, (int) adds, 0, monthDaysTotalInterval.length - 1);

        day = (int) adds - monthDaysTotalInterval[mindex] + 1;
        month = mindex % 12 + 1;
        year = 400 * m400Incr + mindex / 12;
    }

    public int monthDays()
    {
        if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
            return leapMonthDays[month - 1];
        return normalMonthDays[month - 1];
    }

    public static UTC now()
    {
        return new UTC(System.currentTimeMillis());
    }

    public UTC copyFrom(UTC from)
    {
        this.year = from.year;
        this.month = from.month;
        this.day = from.day;
        this.hour = from.hour;
        this.minute = from.minute;
        this.second = from.second;
        this.millisecond = from.millisecond;
        return this;
    }

    public int getYear()
    {
        return year;
    }

    public int getMonth()
    {
        return month;
    }

    public int getDay()
    {
        return day;
    }

    public int getHour()
    {
        return hour;
    }

    public int getMinute()
    {
        return minute;
    }

    public int getSecond()
    {
        return second;
    }

    public int getMillisecond()
    {
        return millisecond;
    }

    public int compareTo(UTC a)
    {
        int v = 0;
        if ((v = this.getYear() - a.getYear()) != 0)
            return v;
        else if ((v = this.getMonth() - a.getMonth()) != 0)
            return v;
        else if ((v = this.getDay() - a.getDay()) != 0)
            return v;
        else if ((v = this.getHour() - a.getHour()) != 0)
            return v;
        else if ((v = this.getMinute() - a.getMinute()) != 0)
            return v;
        else if ((v = this.getSecond() - a.getSecond()) != 0)
            return v;
        else if ((v = this.getMillisecond() - a.getMillisecond()) != 0)
            return v;
        return v;
    }

    @Override
    public String toString()
    {
        return new StringBuilder().append(year).append('/')
                .append(month).append('/')
                .append(day).append(' ')
                .append(hour).append(':')
                .append(minute).append(':')
                .append(second).append(' ')
                .append(millisecond)
                .toString();
    }

    @Override
    public UTC clone()
    {
        return new UTC(year, month, day, hour, minute, second, millisecond);
    }

}

UTCSpan 类


class UTCSpan
{
    private UTC from;
    private UTC to;

    private int centuries;
    private int years;
    private int months;
    private int days;
    private int hours;
    private int minutes;
    private int seconds;
    private int milliseconds;

    public UTCSpan(UTC from, UTC to)
    {
        this.from = from.clone();
        this.to = to.clone();
        Init();
    }

    public UTCSpan(long timeStampFrom, long timestampTo)
    {

    }

    private void Init()
    {
        int cmp = to.compareTo(from);
        if (cmp > 0)
        {
            subtractInit(to, from);
        }
        else if (cmp < 0)
        {
            subtractInit(from, to);
            MakeNegative();
        }
        else
        {
            //do nothing
        }

    }

    private void MakeNegative()
    {
        centuries = -centuries;
        years = -years;
        months = -months;
        days = -days;
        hours = -hours;
        minutes = -minutes;
        seconds = -seconds;
        milliseconds = -milliseconds;
    }

    // a - b (a > b)
    private void subtractInit(UTC a, UTC b)
    {
        int carry = 0;
        milliseconds = a.getMillisecond() - b.getMillisecond();
        if (milliseconds < 0)
        {
            carry = -1;
            milliseconds += 1000;
        }

        seconds = a.getSecond() - b.getSecond() + carry;
        if (seconds < 0)
        {
            carry = -1;
            seconds += 60;
        }
        else
            carry = 0;

        minutes = a.getMinute() - b.getMinute() + carry;
        if (minutes < 0)
        {
            carry = -1;
            minutes += 60;
        }
        else
            carry = 0;

        hours = a.getHour() - b.getHour() + carry;
        if (hours < 0)
        {
            carry = -1;
            hours += 24;
        }
        else
            carry = 0;

        days = a.getDay() - b.getDay() + carry;
        if (days < 0)
        {
            carry = -1;
            days += b.monthDays();
        }
        else
            carry = 0;

        months = a.getMonth() - b.getMonth() + carry;
        if (months < 0)
        {
            carry = -1;
            months += 12;
        }
        else
            carry = 0;

        years = a.getYear() - b.getYear() + carry;

        centuries = years / 100;

        years = years % 100;

    }

    @Override
    public String toString()
    {
        return new StringBuilder()
                .append(centuries).append(' ')
                .append(years).append('/')
                .append(months).append('/')
                .append(days).append(' ')
                .append(hours).append(':')
                .append(minutes).append(':')
                .append(seconds).append(' ')
                .append(milliseconds)
                .toString();
    }


    public String toSpecialString()
    {
        String[] specialSuffix = {"刚刚", "秒前", "分钟前", "小时前", "天前", "个月前", "年前", "个世纪前"};
        int[] tm = {seconds, seconds, minutes, hours, days, months, years, centuries};

        for (int i = tm.length - 1; i > 0; i--)
        {
            if (i > 1 && tm[i] > 0 || i == 1 && tm[i] > 20)
                return tm[i] + specialSuffix[i];
        }

        return specialSuffix[0];
    }
}

测试


public static void main(String[] args) throws InterruptedException
{
    UTC from;
    UTC to;
    UTCSpan sp;

    //20151023153000000
    //20161023152959999
    from = new UTC(2015, 10, 23, 15, 30, 0, 0);
    to = new UTC(2016, 10, 23, 15, 29, 59, 999);
    sp = to.subtract(from);
    System.out.println(sp + "  --->  " + sp.toSpecialString());

    //20151023153000000
    //20161023152000000
    from = new UTC(2015, 10, 23, 15, 30, 0, 0);
    to = new UTC(2016, 10, 23, 15, 30, 0, 0);
    sp = to.subtract(from);
    System.out.println(sp + "  --->  " + sp.toSpecialString());

    //00001023153000000
    //20161023152959999
    from = new UTC(0000, 10, 23, 15, 30, 0, 0);
    to = new UTC(2016, 10, 23, 15, 29, 59, 999);
    sp = to.subtract(from);
    System.out.println(sp + "  --->  " + sp.toSpecialString());

    from = UTC.now();
    while (true)
    {
        Thread.sleep(1000);
        sp = UTC.now().subtract(from);
        System.out.println(sp + "  --->  " + sp.toSpecialString());
    }
}

测试输出


0 0/11/30 23:59:59 999  --->  11个月前

0 1/0/0 0:0:0 0  --->  1年前

20 15/11/30 23:59:59 999  --->  20个世纪前

0 0/0/0 0:0:1 4  --->  刚刚

0 0/0/0 0:0:2 7  --->  刚刚

0 0/0/0 0:0:3 9  --->  刚刚

相关文章

网友评论

      本文标题:Java 时间类 时间间隔类

      本文链接:https://www.haomeiwen.com/subject/qnpdpttx.html