本文整理汇总了Java中com.mysql.jdbc.TimeUtil类的典型用法代码示例。如果您正苦于以下问题:Java TimeUtil类的具体用法?Java TimeUtil怎么用?Java TimeUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TimeUtil类属于com.mysql.jdbc包,在下文中一共展示了TimeUtil类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBug36662
import com.mysql.jdbc.TimeUtil; //导入依赖的package包/类
public void testBug36662() throws Exception {
try {
String tz1 = TimeUtil.getCanonicalTimezone("MEST", null);
assertNotNull(tz1);
} catch (Exception e1) {
String mes1 = e1.getMessage();
mes1 = mes1.substring(mes1.lastIndexOf("The timezones that 'MEST' maps to are:") + 39);
try {
String tz2 = TimeUtil.getCanonicalTimezone("CEST", null);
assertEquals(mes1, tz2);
} catch (Exception e2) {
String mes2 = e2.getMessage();
mes2 = mes2.substring(mes2.lastIndexOf("The timezones that 'CEST' maps to are:") + 39);
assertEquals(mes1, mes2);
}
}
}
示例2: testBug18091639
import com.mysql.jdbc.TimeUtil; //导入依赖的package包/类
/**
* Tests fix for 18091639 - STRINGINDEXOUTOFBOUNDSEXCEPTION IN PREPAREDSTATEMENT.SETTIMESTAMP WITH 5.6.15
*
* @throws Exception
* if the test fails.
*/
public void testBug18091639() throws SQLException {
String str = TimeUtil.formatNanos(1, true, false);
assertEquals("000000001", str);
str = TimeUtil.formatNanos(1, true, true);
assertEquals("0", str);
str = TimeUtil.formatNanos(1999, true, false);
assertEquals("000001999", str);
str = TimeUtil.formatNanos(1999, true, true);
assertEquals("000001", str);
str = TimeUtil.formatNanos(1000000010, true, false);
assertEquals("00000001", str);
str = TimeUtil.formatNanos(1000000010, true, true);
assertEquals("0", str);
}
示例3: testBug36662
import com.mysql.jdbc.TimeUtil; //导入依赖的package包/类
public void testBug36662() throws Exception {
try {
String tz1 = TimeUtil.getCanoncialTimezone("MEST", null);
assertNotNull(tz1);
} catch (Exception e1) {
String mes1 = e1.getMessage();
mes1 = mes1.substring(mes1.lastIndexOf("The timezones that 'MEST' maps to are:")+39);
try {
String tz2 = TimeUtil.getCanoncialTimezone("CEST", null);
assertEquals(mes1, tz2);
} catch (Exception e2) {
String mes2 = e2.getMessage();
mes2 = mes2.substring(mes2.lastIndexOf("The timezones that 'CEST' maps to are:")+39);
assertEquals(mes1, mes2);
}
}
}
示例4: testBug18091639
import com.mysql.jdbc.TimeUtil; //导入依赖的package包/类
/**
* Tests fix for 18091639 - STRINGINDEXOUTOFBOUNDSEXCEPTION IN PREPAREDSTATEMENT.SETTIMESTAMP WITH 5.6.15
*
* @throws Exception
* if the test fails.
*/
public void testBug18091639() throws SQLException {
String str = TimeUtil.formatNanos(1, true, false);
assertEquals("000000001", str);
str = TimeUtil.formatNanos(1, true, true);
assertEquals("0", str);
str = TimeUtil.formatNanos(1999, true, false);
assertEquals("000001999", str);
str = TimeUtil.formatNanos(1999, true, true);
assertEquals("000001", str);
str = TimeUtil.formatNanos(1000000010, true, false);
assertEquals("00000001", str);
str = TimeUtil.formatNanos(1000000010, true, true);
assertEquals("0", str);
}
示例5: main
import com.mysql.jdbc.TimeUtil; //导入依赖的package包/类
/**
* Entry point for program when called from the command line.
*
* @param args
* command-line args. Arg 1 is JDBC URL.
* @throws Exception
* if any errors occur
*/
public static void main(String[] args) throws Exception {
String jdbcUrl = DEFAULT_URL;
if ((args.length == 1) && (args[0] != null)) {
jdbcUrl = args[0];
}
Class.forName("com.mysql.jdbc.Driver").newInstance();
ResultSet rs = null;
try {
rs = DriverManager.getConnection(jdbcUrl).createStatement().executeQuery("SHOW VARIABLES LIKE 'timezone'");
while (rs.next()) {
String timezoneFromServer = rs.getString(2);
System.out.println("MySQL timezone name: " + timezoneFromServer);
String canonicalTimezone = TimeUtil.getCanonicalTimezone(timezoneFromServer, null);
System.out.println("Java timezone name: " + canonicalTimezone);
}
} finally {
if (rs != null) {
rs.close();
}
}
}
示例6: main
import com.mysql.jdbc.TimeUtil; //导入依赖的package包/类
/**
* Entry point for program when called from the command line.
*
* @param args
* command-line args. Arg 1 is JDBC URL.
* @throws Exception
* if any errors occur
*/
public static void main(String[] args) throws Exception {
String jdbcUrl = DEFAULT_URL;
if ((args.length == 1) && (args[0] != null)) {
jdbcUrl = args[0];
}
Class.forName("com.mysql.jdbc.Driver").newInstance();
ResultSet rs = null;
try {
rs = DriverManager.getConnection(jdbcUrl).createStatement().executeQuery("SHOW VARIABLES LIKE 'timezone'");
while (rs.next()) {
String timezoneFromServer = rs.getString(2);
System.out.println("MySQL timezone name: " + timezoneFromServer);
String canonicalTimezone = TimeUtil
.getCanoncialTimezone(timezoneFromServer, null);
System.out.println("Java timezone name: " + canonicalTimezone);
}
} finally {
if (rs != null) {
rs.close();
}
}
}