Commit dfb3454f6ef168ca89ad9b157f075fcc924fe8d1

Authored by panlinlin
1 parent ded82629

修复国标校时的时区的错误导致时间差八个小时

src/main/java/com/genersoft/iot/vmp/gb28181/bean/WvpSipDate.java
1 1 package com.genersoft.iot.vmp.gb28181.bean;
2 2  
  3 +import gov.nist.core.InternalErrorHandler;
3 4 import gov.nist.javax.sip.header.SIPDate;
4 5  
  6 +import java.util.*;
  7 +
5 8 /**
6 9 * 重写jain sip的SIPDate解决与国标时间格式不一致的问题
7 10 */
8 11 public class WvpSipDate extends SIPDate {
9 12  
  13 + private Calendar javaCal;
  14 +
10 15 public WvpSipDate(long timeMillis) {
11   - super(timeMillis);
  16 + this.javaCal = new GregorianCalendar(TimeZone.getDefault(), Locale.getDefault());
  17 + Date date = new Date(timeMillis);
  18 + this.javaCal.setTime(date);
  19 + this.wkday = this.javaCal.get(7);
  20 + switch(this.wkday) {
  21 + case 1:
  22 + this.sipWkDay = "Sun";
  23 + break;
  24 + case 2:
  25 + this.sipWkDay = "Mon";
  26 + break;
  27 + case 3:
  28 + this.sipWkDay = "Tue";
  29 + break;
  30 + case 4:
  31 + this.sipWkDay = "Wed";
  32 + break;
  33 + case 5:
  34 + this.sipWkDay = "Thu";
  35 + break;
  36 + case 6:
  37 + this.sipWkDay = "Fri";
  38 + break;
  39 + case 7:
  40 + this.sipWkDay = "Sat";
  41 + break;
  42 + default:
  43 + InternalErrorHandler.handleException("No date map for wkday " + this.wkday);
  44 + }
  45 +
  46 + this.day = this.javaCal.get(5);
  47 + this.month = this.javaCal.get(2);
  48 + switch(this.month) {
  49 + case 0:
  50 + this.sipMonth = "Jan";
  51 + break;
  52 + case 1:
  53 + this.sipMonth = "Feb";
  54 + break;
  55 + case 2:
  56 + this.sipMonth = "Mar";
  57 + break;
  58 + case 3:
  59 + this.sipMonth = "Apr";
  60 + break;
  61 + case 4:
  62 + this.sipMonth = "May";
  63 + break;
  64 + case 5:
  65 + this.sipMonth = "Jun";
  66 + break;
  67 + case 6:
  68 + this.sipMonth = "Jul";
  69 + break;
  70 + case 7:
  71 + this.sipMonth = "Aug";
  72 + break;
  73 + case 8:
  74 + this.sipMonth = "Sep";
  75 + break;
  76 + case 9:
  77 + this.sipMonth = "Oct";
  78 + break;
  79 + case 10:
  80 + this.sipMonth = "Nov";
  81 + break;
  82 + case 11:
  83 + this.sipMonth = "Dec";
  84 + break;
  85 + default:
  86 + InternalErrorHandler.handleException("No date map for month " + this.month);
  87 + }
  88 +
  89 + this.year = this.javaCal.get(1);
  90 + this.hour = this.javaCal.get(11);
  91 + this.minute = this.javaCal.get(12);
  92 + this.second = this.javaCal.get(13);
12 93 }
13 94  
14 95 @Override
... ...