文档章节

一次 JDBC 与 MySQL 因 “CST” 时区协商误解导致时间差了 14 或 13 小时的排错经历

CasparLi
 CasparLi
发布于 2017/09/22 16:12
字数 4155
阅读 616
收藏 0

CST 时区

名为 CST 的时区是一个很混乱的时区,有四种含义:

  • 美国中部时间 Central Standard Time (USA) UTC-06:00
  • 澳大利亚中部时间 Central Standard Time (Australia) UTC+09:30
  • 中国标准时 China Standard Time UTC+08:00
  • 古巴标准时 Cuba Standard Time UTC-04:00

今天是“4月28日”。为什么提到日期?因为美国从“3月11日”至“11月7日”实行夏令时,美国中部时间改为 UTC-05:00,与 UTC+08:00 相差 13 小时。

排错过程

在项目中,偶然发现数据库中存储的 Timestamp 字段的 unix_timestamp() 值比真实值少了 13 个小时。通过调试追踪,发现了 com.mysql.cj.jdbc 里的时区协商有问题。

当 JDBC 与 MySQL 开始建立连接时,会调用 com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer() 获取服务器参数,其中我们看到调用 this.session.configureTimezone() 函数,它负责配置时区。

public void configureTimezone() {
    String configuredTimeZoneOnServer = getServerVariable("time_zone");

    if ("SYSTEM".equalsIgnoreCase(configuredTimeZoneOnServer)) {
        configuredTimeZoneOnServer = getServerVariable("system_time_zone");
    }

    String canonicalTimezone = getPropertySet().getStringReadableProperty(PropertyDefinitions.PNAME_serverTimezone).getValue();

    if (configuredTimeZoneOnServer != null) {
        // user can override this with driver properties, so don't detect if that's the case
        if (canonicalTimezone == null || StringUtils.isEmptyOrWhitespaceOnly(canonicalTimezone)) {
            try {
                canonicalTimezone = TimeUtil.getCanonicalTimezone(configuredTimeZoneOnServer, getExceptionInterceptor());
            } catch (IllegalArgumentException iae) {
                throw ExceptionFactory.createException(WrongArgumentException.class, iae.getMessage(), getExceptionInterceptor());
            }
        }
    }

    if (canonicalTimezone != null && canonicalTimezone.length() > 0) {
        this.serverTimezoneTZ = TimeZone.getTimeZone(canonicalTimezone);

        // The Calendar class has the behavior of mapping unknown timezones to 'GMT' instead of throwing an exception, so we must check for this...
        if (!canonicalTimezone.equalsIgnoreCase("GMT")
            && this.serverTimezoneTZ.getID().equals("GMT")) {
            throw ...
        }
    }

    this.defaultTimeZone = this.serverTimezoneTZ;
}

追踪代码可知,当 MySQL 的 time_zone 值为 SYSTEM 时,会取 system_time_zone 值作为协调时区。

让我们登录到 MySQL 服务器验证这两个值:

mysql> show variables like '%time_zone%';
+------------------+--------+
| Variable_name    | Value  |
+------------------+--------+
| system_time_zone | CST    |
| time_zone        | SYSTEM |
+------------------+--------+
2 rows in set (0.00 sec)

重点在这里!若 String configuredTimeZoneOnServer 得到的是 CST 那么 Java 会误以为这是 CST -0500 ,因此 TimeZone.getTimeZone(canonicalTimezone) 会给出错误的时区信息。

 debug variables

如图所示,本机默认时区是 Asia/Shanghai +0800 ,误认为服务器时区为 CST -0500 ,实际上服务器是 CST +0800 。

我们会想到,即便时区有误解,如果 Timestamp 是以 long 表示的时间戳传输,也不会出现问题,下面让我们追踪到 com.mysql.cj.jdbc.PreparedStatement.setTimestamp() 。

public void setTimestamp(int parameterIndex, Timestamp x) throws java.sql.SQLException {
    synchronized (checkClosed().getConnectionMutex()) {
        setTimestampInternal(parameterIndex, x, this.session.getDefaultTimeZone());
    }
}

注意到这里 this.session.getDefaultTimeZone() 得到的是刚才那个 CST -0500 。

private void setTimestampInternal(int parameterIndex, Timestamp x, TimeZone tz) throws SQLException {
    if (x == null) {
        setNull(parameterIndex, MysqlType.TIMESTAMP);
    } else {
        if (!this.sendFractionalSeconds.getValue()) {
            x = TimeUtil.truncateFractionalSeconds(x);
        }

        this.parameterTypes[parameterIndex - 1 + getParameterIndexOffset()] = MysqlType.TIMESTAMP;

        if (this.tsdf == null) {
            this.tsdf = new SimpleDateFormat("''yyyy-MM-dd HH:mm:ss", Locale.US);
        }

        this.tsdf.setTimeZone(tz);

        StringBuffer buf = new StringBuffer();
        buf.append(this.tsdf.format(x));
        if (this.session.serverSupportsFracSecs()) {
            buf.append('.');
            buf.append(TimeUtil.formatNanos(x.getNanos(), true));
        }
        buf.append('\'');

        setInternal(parameterIndex, buf.toString());
    }
}

原来 Timestamp 被转换为会话时区的时间字符串了。问题到此已然明晰:

  1. JDBC 误认为会话时区在 CST-5
  2. JBDC 把 Timestamp+0 转为 CST-5 的 String-5
  3. MySQL 认为会话时区在 CST+8,将 String-5 转为 Timestamp-13

最终结果相差 13 个小时!如果处在冬令时还会相差 14 个小时!

解决方案

解决办法也很简单,明确指定 MySQL 数据库的时区,不使用引发误解的 CST :

mysql> set global time_zone = '+08:00';
Query OK, 0 rows affected (0.00 sec)

mysql> set time_zone = '+08:00';
Query OK, 0 rows affected (0.00 sec)

或者修改 my.cnf 文件,在 [mysqld] 节下增加 default-time-zone = '+08:00' 。

修改时区操作影响深远,需要重启 MySQL 服务器,建议在维护时间进行。

===============================================================

另一份解决方案: 

       最近遇到了一个问题,java从mysql从读出的时间与本地时间有14个小时的时间差,经查证、测试解决了此问题,在此总结一下:

 

一、使用mysql-connector-java 6.x版本驱动需要做如下配置:

1、引入pom

1

2

3

4

5

<dependency>

  <groupId>mysql</groupId>

  <artifactId>mysql-connector-java</artifactId>

  <version>6.0.6</version>

</dependency>

 

2、设置jdbc连接、驱动

1

2

3

jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&serverTimezone=UTC&characterEncoding=utf-8&allowMultiQueries=true

com.mysql.cj.jdbc.Driver

 

 

二、设置mysql数据时区

1、查看mysql时区

1

show variables like "%time_zone%"

wKiom1nDVNGAzmOJAAANX4pyPzM345.png

 

2、修改mysql时区

(1)方法一

1

2

3

set global time_zone = '+8:00'; ##修改mysql全局时区为北京时间,即我们所在的东8区

set time_zone = '+8:00'; ##修改当前会话时区

flush privileges; #立即生效

(2)方法二、通过修改my.cnf配置文件来修改时区

1

2

3

# vim /etc/my.cnf ##在[mysqld]区域中加上

default-time_zone = '+8:00'

# /etc/init.d/mysqld restart ##重启mysql使新时区生效

 

三、分析时区设置问题

       通过上面的设置,我们把mysql数据库的时区设置成了中国的时区‘utc+8’,而serverTimezone=UTC设置的是utc时区,两者不同,所以会发现从数据库读出的时间与本地时间差几个小时。要解决这个问题,需要让serverTimezone的设置与数据库的时区保持一致。我们可以选择修改serverTimezone的设置为serverTimezone=Asia/Shanghai,或者修改数据库的时区为‘+0:00’。

 

四、serverTimezone支持的值说明

1、utc时区:serverTimezone=UTC

2、中国时区:serverTimezone=GMT%2B8(GMT+8这种方式支持全部时区,通过修改最后的数字实现,不过%2B不能写成+)

3、查看官方源码,可以看到serverTimezone支持的相关设置如下,如:中国的时区可设置为:serverTimezone=Asia/Shanghai

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

411

412

413

414

415

416

417

418

419

420

421

422

423

424

425

426

427

428

429

430

431

432

433

434

435

436

437

438

439

440

441

442

443

444

445

446

447

448

449

450

451

452

453

454

455

456

457

458

459

460

461

462

463

464

465

466

467

468

469

470

471

472

473

474

475

476

477

478

479

480

481

482

483

484

485

486

487

488

489

490

491

492

493

494

495

496

497

498

499

500

501

502

503

504

505

506

507

508

509

510

511

512

513

514

515

516

517

518

519

520

521

522

523

524

525

526

527

528

529

530

531

#Windows Zones

#Mon Sep 28 16:41:59 WEST 2015

AUS\ Central\ Daylight\ Time=Australia/Darwin

AUS\ Central\ Standard\ Time=Australia/Darwin

AUS\ Eastern\ Daylight\ Time=Australia/Sydney

AUS\ Eastern\ Standard\ Time=Australia/Sydney

Afghanistan\ Daylight\ Time=Asia/Kabul

Afghanistan\ Standard\ Time=Asia/Kabul

Alaskan\ Daylight\ Time=America/Anchorage

Alaskan\ Standard\ Time=America/Anchorage

Arab\ Daylight\ Time=Asia/Riyadh

Arab\ Standard\ Time=Asia/Riyadh

Arabian\ Daylight\ Time=Asia/Dubai

Arabian\ Standard\ Time=Asia/Dubai

Arabic\ Daylight\ Time=Asia/Baghdad

Arabic\ Standard\ Time=Asia/Baghdad

Argentina\ Daylight\ Time=America/Buenos_Aires

Argentina\ Standard\ Time=America/Buenos_Aires

Atlantic\ Daylight\ Time=America/Halifax

Atlantic\ Standard\ Time=America/Halifax

Azerbaijan\ Daylight\ Time=Asia/Baku

Azerbaijan\ Standard\ Time=Asia/Baku

Azores\ Daylight\ Time=Atlantic/Azores

Azores\ Standard\ Time=Atlantic/Azores

Bahia\ Daylight\ Time=America/Bahia

Bahia\ Standard\ Time=America/Bahia

Bangladesh\ Daylight\ Time=Asia/Dhaka

Bangladesh\ Standard\ Time=Asia/Dhaka

Belarus\ Daylight\ Time=Europe/Minsk

Belarus\ Standard\ Time=Europe/Minsk

Canada\ Central\ Daylight\ Time=America/Regina

Canada\ Central\ Standard\ Time=America/Regina

Cape\ Verde\ Daylight\ Time=Atlantic/Cape_Verde

Cape\ Verde\ Standard\ Time=Atlantic/Cape_Verde

Caucasus\ Daylight\ Time=Asia/Yerevan

Caucasus\ Standard\ Time=Asia/Yerevan

Cen.\ Australia\ Daylight\ Time=Australia/Adelaide

Cen.\ Australia\ Standard\ Time=Australia/Adelaide

Central\ America\ Daylight\ Time=America/Guatemala

Central\ America\ Standard\ Time=America/Guatemala

Central\ Asia\ Daylight\ Time=Asia/Almaty

Central\ Asia\ Standard\ Time=Asia/Almaty

Central\ Brazilian\ Daylight\ Time=America/Cuiaba

Central\ Brazilian\ Standard\ Time=America/Cuiaba

Central\ Daylight\ Time=America/Chicago

Central\ Daylight\ Time\ (Mexico)=America/Mexico_City

Central\ Europe\ Daylight\ Time=Europe/Budapest

Central\ Europe\ Standard\ Time=Europe/Budapest

Central\ European\ Daylight\ Time=Europe/Warsaw

Central\ European\ Standard\ Time=Europe/Warsaw

Central\ Pacific\ Daylight\ Time=Pacific/Guadalcanal

Central\ Pacific\ Standard\ Time=Pacific/Guadalcanal

Central\ Standard\ Time=America/Chicago

Central\ Standard\ Time\ (Mexico)=America/Mexico_City

China\ Daylight\ Time=Asia/Shanghai

China\ Standard\ Time=Asia/Shanghai

Dateline\ Daylight\ Time=Etc/GMT+12

Dateline\ Standard\ Time=Etc/GMT+12

E.\ Africa\ Daylight\ Time=Africa/Nairobi

E.\ Africa\ Standard\ Time=Africa/Nairobi

E.\ Australia\ Daylight\ Time=Australia/Brisbane

E.\ Australia\ Standard\ Time=Australia/Brisbane

E.\ South\ America\ Daylight\ Time=America/Sao_Paulo

E.\ South\ America\ Standard\ Time=America/Sao_Paulo

Eastern\ Daylight\ Time=America/New_York

Eastern\ Daylight\ Time\ (Mexico)=America/Cancun

Eastern\ Standard\ Time=America/New_York

Eastern\ Standard\ Time\ (Mexico)=America/Cancun

Egypt\ Daylight\ Time=Africa/Cairo

Egypt\ Standard\ Time=Africa/Cairo

Ekaterinburg\ Daylight\ Time=Asia/Yekaterinburg

Ekaterinburg\ Standard\ Time=Asia/Yekaterinburg

FLE\ Daylight\ Time=Europe/Kiev

FLE\ Standard\ Time=Europe/Kiev

Fiji\ Daylight\ Time=Pacific/Fiji

Fiji\ Standard\ Time=Pacific/Fiji

GMT\ Daylight\ Time=Europe/London

GMT\ Standard\ Time=Europe/London

GTB\ Daylight\ Time=Europe/Bucharest

GTB\ Standard\ Time=Europe/Bucharest

Georgian\ Daylight\ Time=Asia/Tbilisi

Georgian\ Standard\ Time=Asia/Tbilisi

Greenland\ Daylight\ Time=America/Godthab

Greenland\ Standard\ Time=America/Godthab

Greenwich\ Daylight\ Time=Atlantic/Reykjavik

Greenwich\ Standard\ Time=Atlantic/Reykjavik

Hawaiian\ Daylight\ Time=Pacific/Honolulu

Hawaiian\ Standard\ Time=Pacific/Honolulu

India\ Daylight\ Time=Asia/Calcutta

India\ Standard\ Time=Asia/Calcutta

Iran\ Daylight\ Time=Asia/Tehran

Iran\ Standard\ Time=Asia/Tehran

Israel\ Daylight\ Time=Asia/Jerusalem

Israel\ Standard\ Time=Asia/Jerusalem

Jordan\ Daylight\ Time=Asia/Amman

Jordan\ Standard\ Time=Asia/Amman

Kaliningrad\ Daylight\ Time=Europe/Kaliningrad

Kaliningrad\ Standard\ Time=Europe/Kaliningrad

Korea\ Daylight\ Time=Asia/Seoul

Korea\ Standard\ Time=Asia/Seoul

Libya\ Daylight\ Time=Africa/Tripoli

Libya\ Standard\ Time=Africa/Tripoli

Line\ Islands\ Daylight\ Time=Pacific/Kiritimati

Line\ Islands\ Standard\ Time=Pacific/Kiritimati

Magadan\ Daylight\ Time=Asia/Magadan

Magadan\ Standard\ Time=Asia/Magadan

Mauritius\ Daylight\ Time=Indian/Mauritius

Mauritius\ Standard\ Time=Indian/Mauritius

Middle\ East\ Daylight\ Time=Asia/Beirut

Middle\ East\ Standard\ Time=Asia/Beirut

Montevideo\ Daylight\ Time=America/Montevideo

Montevideo\ Standard\ Time=America/Montevideo

Morocco\ Daylight\ Time=Africa/Casablanca

Morocco\ Standard\ Time=Africa/Casablanca

Mountain\ Daylight\ Time=America/Denver

Mountain\ Daylight\ Time\ (Mexico)=America/Chihuahua

Mountain\ Standard\ Time=America/Denver

Mountain\ Standard\ Time\ (Mexico)=America/Chihuahua

Myanmar\ Daylight\ Time=Asia/Rangoon

Myanmar\ Standard\ Time=Asia/Rangoon

N.\ Central\ Asia\ Daylight\ Time=Asia/Novosibirsk

N.\ Central\ Asia\ Standard\ Time=Asia/Novosibirsk

Namibia\ Daylight\ Time=Africa/Windhoek

Namibia\ Standard\ Time=Africa/Windhoek

Nepal\ Daylight\ Time=Asia/Katmandu

Nepal\ Standard\ Time=Asia/Katmandu

New\ Zealand\ Daylight\ Time=Pacific/Auckland

New\ Zealand\ Standard\ Time=Pacific/Auckland

Newfoundland\ Daylight\ Time=America/St_Johns

Newfoundland\ Standard\ Time=America/St_Johns

North\ Asia\ Daylight\ Time=Asia/Krasnoyarsk

North\ Asia\ East\ Daylight\ Time=Asia/Irkutsk

North\ Asia\ East\ Standard\ Time=Asia/Irkutsk

North\ Asia\ Standard\ Time=Asia/Krasnoyarsk

Pacific\ Daylight\ Time=America/Los_Angeles

Pacific\ Daylight\ Time\ (Mexico)=America/Santa_Isabel

Pacific\ SA\ Daylight\ Time=America/Santiago

Pacific\ SA\ Standard\ Time=America/Santiago

Pacific\ Standard\ Time=America/Los_Angeles

Pacific\ Standard\ Time\ (Mexico)=America/Santa_Isabel

Pakistan\ Daylight\ Time=Asia/Karachi

Pakistan\ Standard\ Time=Asia/Karachi

Paraguay\ Daylight\ Time=America/Asuncion

Paraguay\ Standard\ Time=America/Asuncion

Romance\ Daylight\ Time=Europe/Paris

Romance\ Standard\ Time=Europe/Paris

Russia\ Time\ Zone\ 10=Asia/Srednekolymsk

Russia\ Time\ Zone\ 11=Asia/Kamchatka

Russia\ Time\ Zone\ 3=Europe/Samara

Russian\ Daylight\ Time=Europe/Moscow

Russian\ Standard\ Time=Europe/Moscow

SA\ Eastern\ Daylight\ Time=America/Cayenne

SA\ Eastern\ Standard\ Time=America/Cayenne

SA\ Pacific\ Daylight\ Time=America/Bogota

SA\ Pacific\ Standard\ Time=America/Bogota

SA\ Western\ Daylight\ Time=America/La_Paz

SA\ Western\ Standard\ Time=America/La_Paz

SE\ Asia\ Daylight\ Time=Asia/Bangkok

SE\ Asia\ Standard\ Time=Asia/Bangkok

Samoa\ Daylight\ Time=Pacific/Apia

Samoa\ Standard\ Time=Pacific/Apia

Singapore\ Daylight\ Time=Asia/Singapore

Singapore\ Standard\ Time=Asia/Singapore

South\ Africa\ Daylight\ Time=Africa/Johannesburg

South\ Africa\ Standard\ Time=Africa/Johannesburg

Sri\ Lanka\ Daylight\ Time=Asia/Colombo

Sri\ Lanka\ Standard\ Time=Asia/Colombo

Syria\ Daylight\ Time=Asia/Damascus

Syria\ Standard\ Time=Asia/Damascus

Taipei\ Daylight\ Time=Asia/Taipei

Taipei\ Standard\ Time=Asia/Taipei

Tasmania\ Daylight\ Time=Australia/Hobart

Tasmania\ Standard\ Time=Australia/Hobart

Tokyo\ Daylight\ Time=Asia/Tokyo

Tokyo\ Standard\ Time=Asia/Tokyo

Tonga\ Daylight\ Time=Pacific/Tongatapu

Tonga\ Standard\ Time=Pacific/Tongatapu

Turkey\ Daylight\ Time=Europe/Istanbul

Turkey\ Standard\ Time=Europe/Istanbul

US\ Eastern\ Daylight\ Time=America/Indianapolis

US\ Eastern\ Standard\ Time=America/Indianapolis

US\ Mountain\ Daylight\ Time=America/Phoenix

US\ Mountain\ Standard\ Time=America/Phoenix

UTC=Etc/GMT

UTC+12=Etc/GMT-12

UTC-02=Etc/GMT+2

UTC-11=Etc/GMT+11

Ulaanbaatar\ Daylight\ Time=Asia/Ulaanbaatar

Ulaanbaatar\ Standard\ Time=Asia/Ulaanbaatar

Venezuela\ Daylight\ Time=America/Caracas

Venezuela\ Standard\ Time=America/Caracas

Vladivostok\ Daylight\ Time=Asia/Vladivostok

Vladivostok\ Standard\ Time=Asia/Vladivostok

W.\ Australia\ Daylight\ Time=Australia/Perth

W.\ Australia\ Standard\ Time=Australia/Perth

W.\ Central\ Africa\ Daylight\ Time=Africa/Lagos

W.\ Central\ Africa\ Standard\ Time=Africa/Lagos

W.\ Europe\ Daylight\ Time=Europe/Berlin

W.\ Europe\ Standard\ Time=Europe/Berlin

West\ Asia\ Daylight\ Time=Asia/Tashkent

West\ Asia\ Standard\ Time=Asia/Tashkent

West\ Pacific\ Daylight\ Time=Pacific/Port_Moresby

West\ Pacific\ Standard\ Time=Pacific/Port_Moresby

Yakutsk\ Daylight\ Time=Asia/Yakutsk

Yakutsk\ Standard\ Time=Asia/Yakutsk

#Linked Time Zones alias

#Mon Sep 28 16:41:59 WEST 2015

Africa/Addis_Ababa=Africa/Nairobi

Africa/Asmara=Africa/Nairobi

Africa/Asmera=Africa/Nairobi

Africa/Bamako=Africa/Abidjan

Africa/Bangui=Africa/Lagos

Africa/Banjul=Africa/Abidjan

Africa/Blantyre=Africa/Maputo

Africa/Brazzaville=Africa/Lagos

Africa/Bujumbura=Africa/Maputo

Africa/Conakry=Africa/Abidjan

Africa/Dakar=Africa/Abidjan

Africa/Dar_es_Salaam=Africa/Nairobi

Africa/Djibouti=Africa/Nairobi

Africa/Douala=Africa/Lagos

Africa/Freetown=Africa/Abidjan

Africa/Gaborone=Africa/Maputo

Africa/Harare=Africa/Maputo

Africa/Juba=Africa/Khartoum

Africa/Kampala=Africa/Nairobi

Africa/Kigali=Africa/Maputo

Africa/Kinshasa=Africa/Lagos

Africa/Libreville=Africa/Lagos

Africa/Lome=Africa/Abidjan

Africa/Luanda=Africa/Lagos

Africa/Lubumbashi=Africa/Maputo

Africa/Lusaka=Africa/Maputo

Africa/Malabo=Africa/Lagos

Africa/Maseru=Africa/Johannesburg

Africa/Mbabane=Africa/Johannesburg

Africa/Mogadishu=Africa/Nairobi

Africa/Niamey=Africa/Lagos

Africa/Nouakchott=Africa/Abidjan

Africa/Ouagadougou=Africa/Abidjan

Africa/Porto-Novo=Africa/Lagos

Africa/Sao_Tome=Africa/Abidjan

Africa/Timbuktu=Africa/Abidjan

America/Anguilla=America/Port_of_Spain

America/Antigua=America/Port_of_Spain

America/Argentina/ComodRivadavia=America/Argentina/Catamarca

America/Aruba=America/Curacao

America/Atka=America/Adak

America/Buenos_Aires=America/Argentina/Buenos_Aires

America/Catamarca=America/Argentina/Catamarca

America/Coral_Harbour=America/Atikokan

America/Cordoba=America/Argentina/Cordoba

America/Dominica=America/Port_of_Spain

America/Ensenada=America/Tijuana

America/Fort_Wayne=America/Indiana/Indianapolis

America/Grenada=America/Port_of_Spain

America/Guadeloupe=America/Port_of_Spain

America/Indianapolis=America/Indiana/Indianapolis

America/Jujuy=America/Argentina/Jujuy

America/Knox_IN=America/Indiana/Knox

America/Kralendijk=America/Curacao

America/Louisville=America/Kentucky/Louisville

America/Lower_Princes=America/Curacao

America/Marigot=America/Port_of_Spain

America/Mendoza=America/Argentina/Mendoza

America/Montreal=America/Toronto

America/Montserrat=America/Port_of_Spain

America/Porto_Acre=America/Rio_Branco

America/Rosario=America/Argentina/Cordoba

America/Shiprock=America/Denver

America/St_Barthelemy=America/Port_of_Spain

America/St_Kitts=America/Port_of_Spain

America/St_Lucia=America/Port_of_Spain

America/St_Thomas=America/Port_of_Spain

America/St_Vincent=America/Port_of_Spain

America/Tortola=America/Port_of_Spain

America/Virgin=America/Port_of_Spain

Antarctica/McMurdo=Pacific/Auckland

Antarctica/South_Pole=Pacific/Auckland

Arctic/Longyearbyen=Europe/Oslo

Asia/Aden=Asia/Riyadh

Asia/Ashkhabad=Asia/Ashgabat

Asia/Bahrain=Asia/Qatar

Asia/Calcutta=Asia/Kolkata

Asia/Chongqing=Asia/Shanghai

Asia/Chungking=Asia/Shanghai

Asia/Dacca=Asia/Dhaka

Asia/Harbin=Asia/Shanghai

Asia/Istanbul=Europe/Istanbul

Asia/Kashgar=Asia/Urumqi

Asia/Katmandu=Asia/Kathmandu

Asia/Kuwait=Asia/Riyadh

Asia/Macao=Asia/Macau

Asia/Muscat=Asia/Dubai

Asia/Phnom_Penh=Asia/Bangkok

Asia/Saigon=Asia/Ho_Chi_Minh

Asia/Tel_Aviv=Asia/Jerusalem

Asia/Thimbu=Asia/Thimphu

Asia/Ujung_Pandang=Asia/Makassar

Asia/Ulan_Bator=Asia/Ulaanbaatar

Asia/Vientiane=Asia/Bangkok

Atlantic/Faeroe=Atlantic/Faroe

Atlantic/Jan_Mayen=Europe/Oslo

Atlantic/St_Helena=Africa/Abidjan

Australia/ACT=Australia/Sydney

Australia/Canberra=Australia/Sydney

Australia/LHI=Australia/Lord_Howe

Australia/NSW=Australia/Sydney

Australia/North=Australia/Darwin

Australia/Queensland=Australia/Brisbane

Australia/South=Australia/Adelaide

Australia/Tasmania=Australia/Hobart

Australia/Victoria=Australia/Melbourne

Australia/West=Australia/Perth

Australia/Yancowinna=Australia/Broken_Hill

Brazil/Acre=America/Rio_Branco

Brazil/DeNoronha=America/Noronha

Brazil/East=America/Sao_Paulo

Brazil/West=America/Manaus

Canada/Atlantic=America/Halifax

Canada/Central=America/Winnipeg

Canada/East-Saskatchewan=America/Regina

Canada/Eastern=America/Toronto

Canada/Mountain=America/Edmonton

Canada/Newfoundland=America/St_Johns

Canada/Pacific=America/Vancouver

Canada/Saskatchewan=America/Regina

Canada/Yukon=America/Whitehorse

Chile/Continental=America/Santiago

Chile/EasterIsland=Pacific/Easter

Cuba=America/Havana

Egypt=Africa/Cairo

Eire=Europe/Dublin

Europe/Belfast=Europe/London

Europe/Bratislava=Europe/Prague

Europe/Busingen=Europe/Zurich

Europe/Guernsey=Europe/London

Europe/Isle_of_Man=Europe/London

Europe/Jersey=Europe/London

Europe/Ljubljana=Europe/Belgrade

Europe/Mariehamn=Europe/Helsinki

Europe/Nicosia=Asia/Nicosia

Europe/Podgorica=Europe/Belgrade

Europe/San_Marino=Europe/Rome

Europe/Sarajevo=Europe/Belgrade

Europe/Skopje=Europe/Belgrade

Europe/Tiraspol=Europe/Chisinau

Europe/Vaduz=Europe/Zurich

Europe/Vatican=Europe/Rome

Europe/Zagreb=Europe/Belgrade

GB=Europe/London

GB-Eire=Europe/London

GMT+0=Etc/GMT

GMT-0=Etc/GMT

GMT0=Etc/GMT

Greenwich=Etc/GMT

Hongkong=Asia/Hong_Kong

Iceland=Atlantic/Reykjavik

Indian/Antananarivo=Africa/Nairobi

Indian/Comoro=Africa/Nairobi

Indian/Mayotte=Africa/Nairobi

Iran=Asia/Tehran

Israel=Asia/Jerusalem

Jamaica=America/Jamaica

Japan=Asia/Tokyo

Kwajalein=Pacific/Kwajalein

Libya=Africa/Tripoli

Mexico/BajaNorte=America/Tijuana

Mexico/BajaSur=America/Mazatlan

Mexico/General=America/Mexico_City

NZ=Pacific/Auckland

NZ-CHAT=Pacific/Chatham

Navajo=America/Denver

PRC=Asia/Shanghai

Pacific/Johnston=Pacific/Honolulu

Pacific/Midway=Pacific/Pago_Pago

Pacific/Ponape=Pacific/Pohnpei

Pacific/Saipan=Pacific/Guam

Pacific/Samoa=Pacific/Pago_Pago

Pacific/Truk=Pacific/Chuuk

Pacific/Yap=Pacific/Chuuk

Poland=Europe/Warsaw

Portugal=Europe/Lisbon

ROC=Asia/Taipei

ROK=Asia/Seoul

Singapore=Asia/Singapore

Turkey=Europe/Istanbul

UCT=Etc/UCT

US/Alaska=America/Anchorage

US/Aleutian=America/Adak

US/Arizona=America/Phoenix

US/Central=America/Chicago

US/East-Indiana=America/Indiana/Indianapolis

US/Eastern=America/New_York

US/Hawaii=Pacific/Honolulu

US/Indiana-Starke=America/Indiana/Knox

US/Michigan=America/Detroit

US/Mountain=America/Denver

US/Pacific=America/Los_Angeles

US/Pacific-New=America/Los_Angeles

US/Samoa=Pacific/Pago_Pago

Universal=Etc/UTC

W-SU=Europe/Moscow

Zulu=Etc/UTC

#Standard (IANA) abbreviations

#Mon Sep 28 16:41:59 WEST 2015

ACWST=Australia/Eucla

AFT=Asia/Kabul

ALMT=Asia/Almaty

ANAT=Asia/Anadyr

AZOST=Atlantic/Azores

AZOT=Atlantic/Azores

AZST=Asia/Baku

AZT=Asia/Baku

BDT=Asia/Dhaka

BNT=Asia/Brunei

BOT=America/La_Paz

BRST=America/Sao_Paulo

BTT=Asia/Thimphu

CAT=Africa/Maputo

CCT=Indian/Cocos

CHADT=Pacific/Chatham

CHAST=Pacific/Chatham

CHOST=Asia/Choibalsan

CHOT=Asia/Choibalsan

CHUT=Pacific/Chuuk

CKT=Pacific/Rarotonga

COT=America/Bogota

CVT=Atlantic/Cape_Verde

CXT=Indian/Christmas

ChST=Pacific/Guam

DAVT=Antarctica/Davis

DDUT=Antarctica/DumontDUrville

EAST=Pacific/Easter

ECT=America/Guayaquil

EGST=America/Scoresbysund

EGT=America/Scoresbysund

FJST=Pacific/Fiji

FJT=Pacific/Fiji

FKST=Atlantic/Stanley

FNT=America/Noronha

GALT=Pacific/Galapagos

GAMT=Pacific/Gambier

GET=Asia/Tbilisi

GFT=America/Cayenne

GILT=Pacific/Tarawa

GYT=America/Guyana

HDT=America/Adak

HKT=Asia/Hong_Kong

HOVST=Asia/Hovd

HOVT=Asia/Hovd

IDT=Asia/Jerusalem

IOT=Indian/Chagos

IRST=Asia/Tehran

JST=Asia/Tokyo

KGT=Asia/Bishkek

KOST=Pacific/Kosrae

LHDT=Australia/Lord_Howe

LHST=Australia/Lord_Howe

LINT=Pacific/Kiritimati

MAGT=Asia/Magadan

MART=Pacific/Marquesas

MAWT=Antarctica/Mawson

MEST=MET

MET=MET

MIST=Antarctica/Macquarie

MMT=Asia/Rangoon

MUT=Indian/Mauritius

MVT=Indian/Maldives

NCT=Pacific/Noumea

NDT=America/St_Johns

NFT=Pacific/Norfolk

NOVT=Asia/Novosibirsk

NPT=Asia/Kathmandu

NRT=Pacific/Nauru

NST=America/St_Johns

NUT=Pacific/Niue

NZDT=Pacific/Auckland

NZST=Pacific/Auckland

OMST=Asia/Omsk

ORAT=Asia/Oral

PET=America/Lima

PETT=Asia/Kamchatka

PGT=Pacific/Port_Moresby

PHOT=Pacific/Enderbury

PHT=Asia/Manila

PKT=Asia/Karachi

PMDT=America/Miquelon

PMST=America/Miquelon

PONT=Pacific/Pohnpei

PWT=Pacific/Palau

PYST=America/Asuncion

PYT=America/Asuncion

QYZT=Asia/Qyzylorda

RET=Indian/Reunion

ROTT=Antarctica/Rothera

SAKT=Asia/Sakhalin

SAMT=Europe/Samara

SAST=Africa/Johannesburg

SBT=Pacific/Guadalcanal

SCT=Indian/Mahe

SGT=Asia/Singapore

SRET=Asia/Srednekolymsk

SRT=America/Paramaribo

SST=Pacific/Pago_Pago

SYOT=Antarctica/Syowa

TAHT=Pacific/Tahiti

TFT=Indian/Kerguelen

TJT=Asia/Dushanbe

TKT=Pacific/Fakaofo

TLT=Asia/Dili

TMT=Asia/Ashgabat

TOT=Pacific/Tongatapu

TVT=Pacific/Funafuti

ULAST=Asia/Ulaanbaatar

ULAT=Asia/Ulaanbaatar

UYT=America/Montevideo

VET=America/Caracas

VOST=Antarctica/Vostok

VUT=Pacific/Efate

WAKT=Pacific/Wake

WAST=Africa/Windhoek

WFT=Pacific/Wallis

WGST=America/Godthab

WGT=America/Godthab

WIT=Asia/Jayapura

WITA=Asia/Makassar

WSDT=Pacific/Apia

WSST=Pacific/Apia

XJT=Asia/Urumqi

YEKT=Asia/Yekaterinburg

以上内容在src\main\resources\com\mysql\cj\jdbc\util.TimeZoneMapping.properties,

= 后面的值为我们可以用来设置的值

本文出自 “星技传阅” 博客,请务必保留此出处http://snowtiger.blog.51cto.com/12931578/1967441

本文转载自:http://www.cnblogs.com/bgo-tech/p/6929701.html

CasparLi
粉丝 15
博文 132
码字总数 26994
作品 0
成都
程序员
私信 提问
JavaWeb 项目与系统时间相差 8 个小时的问题

写在前面 今天记录分享一个排查部署到 Linux 上的 web 项目执行的时间和本地系统时间相差 8 小时的问题 环境:redhat 6.5 考虑有规律的时间差可能和时区不同有关 1 查看 Linux 系统时间和时区...

charmsongo
03/31
0
0
部署在Tomcat 服务器中的web应用读取时间与系统时间不一致问题 【靠谱】

我在部署应用到Ubantu系统上的tomcat服务器中运行,发现操作系统的时间和tomcat中的应用程序获取的时间不一致,总是相差8个小时,但是查看当前操作系统的时区也是CST时区(中国标准时区)。 ...

Airship
04/22
0
0
mysql中时间数据差14小时

问题 调试代码中,确定了出来的时间数据是准确了,没有出现差14小时情况,通过Spring hibernate jdbc这一路保存到mysql数据库中,就出现了14小时问题。 排查 mysql排查 到这里,基本上排除了...

亚林瓜子
2018/12/18
0
0
【Mysql】利用Mybatis3连接mysql获取datetime类型数据错误

mysql版本:myql-connector-java-8.0.11.jar mybatis3连接数据库代码如下: 执行结果: OPTDATATIME为数据库实际结果(OPTDATATIME是转为字符串取出的数据)。OPT_DATETIME0为Java自动转类型...

大白来袭
2018/11/29
0
0
数据库保存时间为什么用long最好

数据库节省空间 好比较 无时区和夏令时冬令时问题 解决闰秒问题 解决历史遗留问题和国家特殊性问题 (教皇格列高里十三世于1582年宣布改历。先是一步到位把儒略历1582年10月4日的下一天定为格...

恶魔永生
2015/01/13
0
3

没有更多内容

加载失败,请刷新页面

加载更多

Leetcode PHP题解--D88 696. Count Binary Substrings

D88 696. Count Binary Substrings 题目链接 696. Count Binary Substrings 题目分析 给定一个01字符串,返回仅用连续的0和1串所能组成的二进制字符串个数。 例如,00110011,就包含0011,0...

skys215
今天
2
0
基础工具类

package com.atguigu.util;import java.sql.Connection;import java.sql.SQLException;import java.util.Properties;import javax.sql.DataSource;import com.alibaba.druid......

architect刘源源
今天
52
0
P30 Pro劲敌!DxO官宣新机:排行榜又要变

5月26日晚间,DxOMark官方推特预告,将在5月27日公布一款新机型的DxOMark评分,猜猜是哪款? 网友猜想的机型有:红米K20、谷歌Pixel 3a、索尼Xperia 1、诺基亚9 PureView等。 DxOMark即将公布...

linux-tao
昨天
18
0
Ubuntu18.04.2窗口过小不能自适应(二次转载)

解决Ubuntu在虚拟机窗口不能自适应 2018年09月06日 16:20:08 起不了名儿 阅读数 855 此博文转载:https://blog.csdn.net/nuddlle/article/details/77994080(原地址) 试了很多办法这个好用 ...

tahiti_aa
昨天
2
0
死磕 java同步系列之CountDownLatch源码解析

问题 (1)CountDownLatch是什么? (2)CountDownLatch具有哪些特性? (3)CountDownLatch通常运用在什么场景中? (4)CountDownLatch的初始次数是否可以调整? 简介 CountDownLatch,可以...

彤哥读源码
昨天
8
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部