WvpSipDate.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. package com.genersoft.iot.vmp.gb28181.bean;
  2. import gov.nist.core.InternalErrorHandler;
  3. import gov.nist.javax.sip.header.SIPDate;
  4. import java.util.*;
  5. /**
  6. * 重写jain sip的SIPDate解决与国标时间格式不一致的问题
  7. */
  8. public class WvpSipDate extends SIPDate {
  9. /**
  10. *
  11. */
  12. private static final long serialVersionUID = 1L;
  13. private Calendar javaCal;
  14. public WvpSipDate(long timeMillis) {
  15. this.javaCal = new GregorianCalendar(TimeZone.getDefault(), Locale.getDefault());
  16. Date date = new Date(timeMillis);
  17. this.javaCal.setTime(date);
  18. this.wkday = this.javaCal.get(7);
  19. switch(this.wkday) {
  20. case 1:
  21. this.sipWkDay = "Sun";
  22. break;
  23. case 2:
  24. this.sipWkDay = "Mon";
  25. break;
  26. case 3:
  27. this.sipWkDay = "Tue";
  28. break;
  29. case 4:
  30. this.sipWkDay = "Wed";
  31. break;
  32. case 5:
  33. this.sipWkDay = "Thu";
  34. break;
  35. case 6:
  36. this.sipWkDay = "Fri";
  37. break;
  38. case 7:
  39. this.sipWkDay = "Sat";
  40. break;
  41. default:
  42. InternalErrorHandler.handleException("No date map for wkday " + this.wkday);
  43. }
  44. this.day = this.javaCal.get(5);
  45. this.month = this.javaCal.get(2);
  46. switch(this.month) {
  47. case 0:
  48. this.sipMonth = "Jan";
  49. break;
  50. case 1:
  51. this.sipMonth = "Feb";
  52. break;
  53. case 2:
  54. this.sipMonth = "Mar";
  55. break;
  56. case 3:
  57. this.sipMonth = "Apr";
  58. break;
  59. case 4:
  60. this.sipMonth = "May";
  61. break;
  62. case 5:
  63. this.sipMonth = "Jun";
  64. break;
  65. case 6:
  66. this.sipMonth = "Jul";
  67. break;
  68. case 7:
  69. this.sipMonth = "Aug";
  70. break;
  71. case 8:
  72. this.sipMonth = "Sep";
  73. break;
  74. case 9:
  75. this.sipMonth = "Oct";
  76. break;
  77. case 10:
  78. this.sipMonth = "Nov";
  79. break;
  80. case 11:
  81. this.sipMonth = "Dec";
  82. break;
  83. default:
  84. InternalErrorHandler.handleException("No date map for month " + this.month);
  85. }
  86. this.year = this.javaCal.get(1);
  87. this.hour = this.javaCal.get(11);
  88. this.minute = this.javaCal.get(12);
  89. this.second = this.javaCal.get(13);
  90. }
  91. @Override
  92. public StringBuilder encode(StringBuilder var1) {
  93. String var2;
  94. if (this.month < 9) {
  95. var2 = "0" + (this.month + 1);
  96. } else {
  97. var2 = "" + (this.month + 1);
  98. }
  99. String var3;
  100. if (this.day < 10) {
  101. var3 = "0" + this.day;
  102. } else {
  103. var3 = "" + this.day;
  104. }
  105. String var4;
  106. if (this.hour < 10) {
  107. var4 = "0" + this.hour;
  108. } else {
  109. var4 = "" + this.hour;
  110. }
  111. String var5;
  112. if (this.minute < 10) {
  113. var5 = "0" + this.minute;
  114. } else {
  115. var5 = "" + this.minute;
  116. }
  117. String var6;
  118. if (this.second < 10) {
  119. var6 = "0" + this.second;
  120. } else {
  121. var6 = "" + this.second;
  122. }
  123. int var8 = this.javaCal.get(14);
  124. String var7;
  125. if (var8 < 10) {
  126. var7 = "00" + var8;
  127. } else if (var8 < 100) {
  128. var7 = "0" + var8;
  129. } else {
  130. var7 = "" + var8;
  131. }
  132. return var1.append(this.year).append("-").append(var2).append("-").append(var3).append("T").append(var4).append(":").append(var5).append(":").append(var6).append(".").append(var7);
  133. }
  134. }