{"id":337,"date":"2025-09-08T10:22:03","date_gmt":"2025-09-08T01:22:03","guid":{"rendered":"https:\/\/i-third.org\/blog\/?p=337"},"modified":"2025-09-08T10:22:03","modified_gmt":"2025-09-08T01:22:03","slug":"java%e3%82%a8%e3%83%b3%e3%82%b8%e3%83%8b%e3%82%a2%e5%bf%85%e8%a6%8b%ef%bc%81%e6%97%a5%e6%99%82%e7%ae%a1%e7%90%86%e3%82%aa%e3%83%96%e3%82%b8%e3%82%a7%e3%82%af%e3%83%88%e3%81%ae%e6%ad%b4%e5%8f%b2","status":"publish","type":"post","link":"https:\/\/i-third.org\/blog\/?p=337","title":{"rendered":"Java\u30a8\u30f3\u30b8\u30cb\u30a2\u5fc5\u898b\uff01\u65e5\u6642\u7ba1\u7406\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u6b74\u53f2\u3068\u6700\u65b0Java\u3067\u5931\u6557\u3057\u306a\u30445\u3064\u306e\u9244\u5247"},"content":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\u3001\u30d6\u30ed\u30b0\u7de8\u96c6\u9577\u306e\u4f50\u85e4\u3067\u3059\u3002\u79c1\u306f\u3053\u308c\u307e\u306720\u5e74\u4ee5\u4e0a\u30b7\u30b9\u30c6\u30e0\u958b\u767a\u306b\u643a\u308f\u3063\u3066\u304d\u305f\u73fe\u5f79\u30b7\u30b9\u30c6\u30e0\u30a8\u30f3\u30b8\u30cb\u30a2\u3067\u3042\u308a\u3001\u73fe\u5728\u306fIT\u696d\u754c\u3067\u30ad\u30e3\u30ea\u30a2\u30b3\u30f3\u30b5\u30eb\u30bf\u30f3\u30c8\u3068\u3057\u3066\u3082\u6d3b\u52d5\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u591a\u304f\u306eJava\u958b\u767a\u8005\u304c\u982d\u3092\u60a9\u307e\u305b\u308b\u554f\u984c\u306e\u4e00\u3064\u306b\u3001\u300c\u65e5\u6642\uff08\u65e5\u4ed8\u3068\u6642\u523b\uff09\u300d\u306e\u6271\u3044\u306e\u96e3\u3057\u3055\u304c\u3042\u308a\u307e\u3059\u3002\u4e00\u53e3\u306b\u300c\u6642\u9593\u300d\u3068\u8a00\u3063\u3066\u3082\u3001\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u3001\u590f\u6642\u9593\u3001\u3046\u308b\u3046\u79d2\u306a\u3069\u8003\u616e\u3059\u3079\u304d\u3053\u3068\u304c\u5c71\u307b\u3069\u3042\u308a\u3001\u5c11\u3057\u306e\u30df\u30b9\u304c\u30b7\u30b9\u30c6\u30e0\u5168\u4f53\u306e\u4e0d\u5177\u5408\u306b\u3064\u306a\u304c\u308b\u3053\u3068\u3082\u5c11\u306a\u304f\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n<p>\u3057\u304b\u3057\u3001\u3054\u5b89\u5fc3\u304f\u3060\u3055\u3044\u3002\u3053\u306e\u8a18\u4e8b\u3067\u306f\u3001Java\u306e\u65e5\u6642\u7ba1\u7406\u304c\u3069\u306e\u3088\u3046\u306b\u9032\u5316\u3057\u3066\u304d\u305f\u306e\u304b\u3092\u3072\u3082\u89e3\u304d\u3001\u73fe\u5728\u63a8\u5968\u3055\u308c\u3066\u3044\u308b<strong><code>java.time<\/code><\/strong> API\u306e\u5177\u4f53\u7684\u306a\u4f7f\u3044\u65b9\u307e\u3067\u3001\u521d\u5fc3\u8005\u306e\u65b9\u3067\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u306b\u5fb9\u5e95\u89e3\u8aac\u3057\u307e\u3059\u3002\u3053\u306e\u8a18\u4e8b\u3092\u8aad\u3081\u3070\u3001<strong>\u306a\u305c\u53e4\u3044API\u304c\u975e\u63a8\u5968\u306a\u306e\u304b<\/strong>\u3001\u305d\u3057\u3066<strong>\u6700\u65b0\u306eJava\u3067\u3069\u306e\u3088\u3046\u306b\u6642\u9593\u3092\u6271\u3046\u306e\u304c\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9\u306a\u306e\u304b<\/strong>\u3092\u5b8c\u5168\u306b\u7406\u89e3\u3057\u3001\u4eca\u65e5\u304b\u3089\u3042\u306a\u305f\u306e\u30b3\u30fc\u30c9\u3092\u3088\u308a\u5805\u7262\u306a\u3082\u306e\u306b\u3067\u304d\u307e\u3059\u3002\u3055\u3042\u3001\u4e00\u7dd2\u306b\u65e5\u6642\u7ba1\u7406\u306e\u60a9\u307f\u3092\u89e3\u6c7a\u3057\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002\n<\/p>\n<hr>\n<h2>\u76ee\u6b21<br \/><\/h2>\n<ul>\n<li><a href=\"#section-1\">\u306a\u305c\u65e5\u6642\u7ba1\u7406\u306f\u96e3\u3057\u3044\u306e\u304b\uff1fJava\u306e\u6b74\u53f2\u3092\u632f\u308a\u8fd4\u308b<\/a><\/li>\n<li><a href=\"#section-2\">Java 8\u3067\u767b\u5834\uff01\u65b0\u6642\u4ee3\u3092\u7bc9\u3044\u305f\u300cjava.time\u300dAPI\u306e\u6982\u8981<\/a><\/li>\n<li><a href=\"#section-3\">\u3010\u5b9f\u8df5\u3011\u6700\u65b0Java\uff08Java 21\u4ee5\u964d\uff09\u3067\u306e\u65e5\u6642\u7ba1\u7406\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9<\/a><\/li>\n<li><a href=\"#section-4\">\u5b9f\u8df5\u4f8b\uff1a\u65e5\u6642\u60c5\u5831\u3092\u53d6\u5f97\u30fb\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3059\u308b\u5177\u4f53\u7684\u306a\u624b\u9806<\/a><\/li>\n<li><a href=\"#section-5\">\u307e\u3068\u3081\uff1a\u65e5\u6642\u7ba1\u7406\u306e\u672a\u6765\u3068\u3042\u306a\u305f\u306e\u30ad\u30e3\u30ea\u30a2<\/a><\/li>\n<\/ul>\n<hr>\n<h2 id=\"section-1\"><strong>\u306a\u305c\u65e5\u6642\u7ba1\u7406\u306f\u96e3\u3057\u3044\u306e\u304b\uff1fJava\u306e\u6b74\u53f2\u3092\u632f\u308a\u8fd4\u308b<\/strong><br \/><\/h2>\n<p>\n<br \/>Java\u306b\u9577\u304f\u643a\u308f\u3063\u3066\u3044\u308b\u30a8\u30f3\u30b8\u30cb\u30a2\u306a\u3089\u3001\u300c<strong><code>java.util.Date<\/code><\/strong>\u300d\u3084\u300c<strong><code>java.util.Calendar<\/code><\/strong>\u300d\u3068\u3044\u3063\u305f\u30af\u30e9\u30b9\u3092\u4f7f\u3063\u305f\u3053\u3068\u304c\u3042\u308b\u3067\u3057\u3087\u3046\u3002\u3053\u308c\u3089\u306fJava\u306e\u521d\u671f\u304b\u3089\u5b58\u5728\u3057\u305f\u65e5\u6642\u7ba1\u7406\u306e\u305f\u3081\u306eAPI\u3067\u3059\u304c\u3001\u5b9f\u306f\u591a\u304f\u306e\u554f\u984c\u3092\u62b1\u3048\u3066\u3044\u307e\u3057\u305f\u3002<\/p>\n<p>\u4e3b\u306a\u554f\u984c\u70b9\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\u3002<\/p>\n<ul>\n<li><strong>\u53ef\u5909\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3067\u3042\u308b\u3053\u3068<\/strong>: \u4e00\u5ea6\u751f\u6210\u3057\u305f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u5024\u3092\u5909\u66f4\u3067\u304d\u3066\u3057\u307e\u3046\u305f\u3081\u3001\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u3067\u306f\u306a\u304f\u3001\u610f\u56f3\u3057\u306a\u3044\u5909\u66f4\u304c\u8d77\u3053\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3057\u305f\u3002<\/li>\n<li><strong>\u8a2d\u8a08\u306e\u4e0d\u6574\u5408\u6027<\/strong>: <strong><code>Date<\/code><\/strong>\u30af\u30e9\u30b9\u304c\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u3092\u6301\u305f\u305a\u3001<strong><code>Calendar<\/code><\/strong>\u30af\u30e9\u30b9\u304c\u8907\u96d1\u3059\u304e\u308b\u306a\u3069\u3001\u4f7f\u3044\u3065\u3089\u3055\u304c\u76ee\u7acb\u3061\u307e\u3057\u305f\u3002<\/li>\n<li><strong>\u76f4\u611f\u306b\u53cd\u3059\u308b\u6319\u52d5<\/strong>: \u6708\u304c0\u304b\u3089\u59cb\u307e\u308b\u306a\u3069\u3001\u958b\u767a\u8005\u306b\u3068\u3063\u3066\u76f4\u611f\u7684\u3067\u306a\u3044\u4ed5\u69d8\u304c\u591a\u304f\u3001\u30d0\u30b0\u306e\u539f\u56e0\u3068\u306a\u308a\u3084\u3059\u304b\u3063\u305f\u306e\u3067\u3059\u3002<\/li>\n<\/ul>\n<p>\u3053\u308c\u3089\u306e\u554f\u984c\u3092\u89e3\u6c7a\u3059\u308b\u305f\u3081\u3001Java 8\u3067\u5168\u304f\u65b0\u3057\u3044\u65e5\u6642API\u300c<strong><code>java.time<\/code><\/strong>\u300d\u304c\u5c0e\u5165\u3055\u308c\u307e\u3057\u305f\u3002\u3053\u306e\u5909\u9769\u306f\u3001Java\u958b\u767a\u306b\u304a\u3051\u308b\u65e5\u6642\u7ba1\u7406\u3092\u6839\u672c\u304b\u3089\u6539\u5584\u3059\u308b\u3082\u306e\u3067\u3057\u305f\u3002\n<\/p>\n<hr>\n<h2 id=\"section-2\"><strong>Java 8\u3067\u767b\u5834\uff01\u65b0\u6642\u4ee3\u3092\u7bc9\u3044\u305f\u300cjava.time\u300dAPI\u306e\u6982\u8981<\/strong><br \/><\/h2>\n<p>\n<br \/>Java 8\u3067\u5c0e\u5165\u3055\u308c\u305f<strong><code>java.time<\/code><\/strong> API\u306f\u3001\u3053\u308c\u3089\u306e\u554f\u984c\u3092\u3059\u3079\u3066\u89e3\u6c7a\u3057\u307e\u3057\u305f\u3002\u3053\u306eAPI\u306e\u8a2d\u8a08\u601d\u60f3\u306f\u300c<strong>\u4e0d\u5909\u6027\uff08Immutable\uff09<\/strong>\u300d\u3068\u300c<strong>\u660e\u78ba\u6027\uff08Clarity\uff09<\/strong>\u300d\u3067\u3059\u3002<\/p>\n<p>\u4e3b\u306a\u30af\u30e9\u30b9\u3068\u305d\u306e\u5f79\u5272\u3092\u898b\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<ul>\n<li><strong><code>LocalDate<\/code><\/strong>: \u65e5\u4ed8\u306e\u307f\uff08\u5e74\u3001\u6708\u3001\u65e5\uff09\u3092\u6271\u3044\u307e\u3059\u3002<\/li>\n<li><strong><code>LocalTime<\/code><\/strong>: \u6642\u9593\u306e\u307f\uff08\u6642\u3001\u5206\u3001\u79d2\u3001\u30ca\u30ce\u79d2\uff09\u3092\u6271\u3044\u307e\u3059\u3002<\/li>\n<li><strong><code>LocalDateTime<\/code><\/strong>: \u65e5\u4ed8\u3068\u6642\u9593\u3092\u7d44\u307f\u5408\u308f\u305b\u307e\u3059\u3002\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u60c5\u5831\u306f\u6301\u3061\u307e\u305b\u3093\u3002<\/li>\n<li><strong><code>ZonedDateTime<\/code><\/strong>: \u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u60c5\u5831\u3092\u542b\u3093\u3060\u65e5\u6642\u3092\u6271\u3044\u307e\u3059\u3002<\/li>\n<li><strong><code>Instant<\/code><\/strong>: 1970\u5e741\u67081\u65e500:00:00 UTC\u304b\u3089\u306e\u7d4c\u904e\u6642\u9593\u3092\u30ca\u30ce\u79d2\u5358\u4f4d\u3067\u8868\u3057\u307e\u3059\u3002<\/li>\n<\/ul>\n<p>\u3053\u306e\u3088\u3046\u306b\u3001\u7528\u9014\u306b\u5fdc\u3058\u3066\u30af\u30e9\u30b9\u304c\u660e\u78ba\u306b\u5206\u304b\u308c\u3066\u3044\u308b\u305f\u3081\u3001\u3069\u306e\u30af\u30e9\u30b9\u3092\u4f7f\u3048\u3070\u3044\u3044\u304b\u8ff7\u3046\u3053\u3068\u304c\u6e1b\u308a\u3001\u610f\u56f3\u3057\u306a\u3044\u30d0\u30b0\u3082\u9632\u3052\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002\n<\/p>\n<hr>\n<h2 id=\"section-3\"><strong>\u3010\u5b9f\u8df5\u3011\u6700\u65b0Java\uff08Java 21\u4ee5\u964d\uff09\u3067\u306e\u65e5\u6642\u7ba1\u7406\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9<\/strong><br \/><\/h2>\n<p>\n<br \/>\u3053\u3053\u304b\u3089\u306f\u3001\u6700\u65b0\u306eJava\u74b0\u5883\u3067\u65e5\u6642\u3092\u6271\u3046\u969b\u306e\u5177\u4f53\u7684\u306a\u9244\u5247\u3068\u624b\u9806\u3092\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n<p>### 1. \u65e5\u6642\u60c5\u5831\u306e\u53d6\u5f97<br \/>\n\u73fe\u5728\u306e\u65e5\u6642\u3092\u53d6\u5f97\u3059\u308b\u969b\u306f\u3001\u5404\u30af\u30e9\u30b9\u306e**<code>now()<\/code>**\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3059\u308b\u306e\u304c\u57fa\u672c\u3067\u3059\u3002\n<\/p>\n<pre>\n<code>\n\/\/ \u73fe\u5728\u306e\u65e5\u4ed8\u3092\u53d6\u5f97\nLocalDate today = LocalDate.now();\nSystem.out.println(\"\u4eca\u65e5\u306e\u65e5\u4ed8: \" + today);\n\n\/\/ \u73fe\u5728\u306e\u6642\u523b\u3092\u53d6\u5f97\nLocalTime nowTime = LocalTime.now();\nSystem.out.println(\"\u73fe\u5728\u306e\u6642\u523b: \" + nowTime);\n\n\/\/ \u73fe\u5728\u306e\u65e5\u6642\u3092\u53d6\u5f97\nLocalDateTime now = LocalDateTime.now();\nSystem.out.println(\"\u73fe\u5728\u306e\u65e5\u6642: \" + now);\n\n\/\/ \u73fe\u5728\u306e\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u4ed8\u304d\u65e5\u6642\u3092\u53d6\u5f97\nZonedDateTime nowZoned = ZonedDateTime.now();\nSystem.out.println(\"\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u4ed8\u304d\u65e5\u6642: \" + nowZoned);\n\n\/\/ UTC\u306e\u77ac\u6642\u3092\u53d6\u5f97\nInstant nowInstant = Instant.now();\nSystem.out.println(\"\u73fe\u5728\u306eUTC\u77ac\u9593: \" + nowInstant);\n<\/code>\n<\/pre>\n<p>\n<br \/>### 2. \u65e5\u6642\u306e\u64cd\u4f5c<br \/>\n<strong><code>java.time<\/code><\/strong> API\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f<strong>\u4e0d\u5909<\/strong>\u3067\u3042\u308b\u305f\u3081\u3001\u5024\u3092\u5909\u66f4\u3059\u308b\u969b\u306f\u65b0\u3057\u3044\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u8fd4\u3055\u308c\u307e\u3059\u3002\u3053\u308c\u306b\u3088\u308a\u3001\u5143\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u610f\u56f3\u305b\u305a\u5909\u66f4\u3055\u308c\u308b\u3053\u3068\u3092\u9632\u3052\u307e\u3059\u3002\n<\/p>\n<pre>\n<code>\nLocalDateTime now = LocalDateTime.now();\n\/\/ 1\u65e5\u5f8c\nLocalDateTime nextDay = now.plusDays(1);\n\/\/ 1\u6642\u9593\u5f8c\nLocalDateTime nextHour = now.plusHours(1);\n\/\/ 1\u30f6\u6708\u524d\nLocalDateTime lastMonth = now.minusMonths(1);\n<\/code>\n<\/pre>\n<p>\n<br \/>### 3. \u65e5\u6642\u60c5\u5831\u306e\u30d5\u30a9\u30fc\u30de\u30c3\u30c8<br \/>\n\u65e5\u6642\u306e\u8868\u793a\u5f62\u5f0f\u3092\u81ea\u7531\u306b\u5909\u3048\u308b\u306b\u306f\u3001**<code>DateTimeFormatter<\/code>\u30af\u30e9\u30b9\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002\n<\/p>\n<pre>\n<code>\nLocalDateTime now = LocalDateTime.now();\n\/\/ yyyy\/MM\/dd HH:mm:ss \u5f62\u5f0f\u306b\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\nDateTimeFormatter formatter = DateTimeFormatter.ofPattern(\"yyyy\/MM\/dd HH:mm:ss\");\nString formattedDate = now.format(formatter);\nSystem.out.println(\"\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3055\u308c\u305f\u65e5\u6642: \" + formattedDate);\n<\/code>\n<\/pre>\n<p>\n<br \/>### 4. \u6587\u5b57\u5217\u304b\u3089\u65e5\u6642\u3078\u306e\u30d1\u30fc\u30b9<br \/>\n\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3084\u5916\u90e8\u30b7\u30b9\u30c6\u30e0\u304b\u3089\u53d7\u3051\u53d6\u3063\u305f\u6587\u5b57\u5217\u3092\u65e5\u6642\u306b\u5909\u63db\u3059\u308b\u5834\u5408\u3082\u3001<code>DateTimeFormatter<\/code>**\u304c\u6d3b\u8e8d\u3057\u307e\u3059\u3002\n<\/p>\n<pre>\n<code>\nString dateStr = \"2025-09-08T10:30:00\";\nLocalDateTime parsedDate = LocalDateTime.parse(dateStr);\nSystem.out.println(\"\u30d1\u30fc\u30b9\u3055\u308c\u305f\u65e5\u6642: \" + parsedDate);\n\n\/\/ \u7279\u5b9a\u306e\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u304b\u3089\u30d1\u30fc\u30b9\nString formattedStr = \"2025\/09\/08 10:30:00\";\nDateTimeFormatter formatter = DateTimeFormatter.ofPattern(\"yyyy\/MM\/dd HH:mm:ss\");\nLocalDateTime parsedFromFormatted = LocalDateTime.parse(formattedStr, formatter);\nSystem.out.println(\"\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u304b\u3089\u30d1\u30fc\u30b9: \" + parsedFromFormatted);\n<\/code>\n<\/pre>\n<p>\n<br \/>### 5. MySQL\u3068\u306e\u9023\u643a<br \/>\n\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u65e5\u6642\u3092\u4fdd\u5b58\u3059\u308b\u5834\u5408\u3001Java\u306e\u30af\u30e9\u30b9\u3068MySQL\u306e\u30c7\u30fc\u30bf\u578b\u3092\u6b63\u3057\u304f\u5bfe\u5fdc\u3055\u305b\u308b\u3053\u3068\u304c\u91cd\u8981\u3067\u3059\u3002\n<\/p>\n<p>\n<\/p>\n<table>\n<thead>\n<tr>\n<th>Java\u30af\u30e9\u30b9<\/th>\n<th>MySQL\u578b<\/th>\n<th>\u30e6\u30fc\u30b9\u30b1\u30fc\u30b9<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong><code>java.time.LocalDate<\/code><\/strong><\/td>\n<td><code>DATE<\/code><\/td>\n<td>\u8a95\u751f\u65e5\u306a\u3069\u3001\u65e5\u4ed8\u306e\u307f\u3092\u4fdd\u5b58\u3059\u308b\u5834\u5408<\/td>\n<\/tr>\n<tr>\n<td><strong><code>java.time.LocalDateTime<\/code><\/strong><\/td>\n<td><code>DATETIME(6)<\/code><\/td>\n<td>\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u3092\u610f\u8b58\u3057\u306a\u3044\u65e5\u6642\u3092\u4fdd\u5b58\u3059\u308b\u5834\u5408<\/td>\n<\/tr>\n<tr>\n<td><strong><code>java.time.Instant<\/code><\/strong><\/td>\n<td><code>TIMESTAMP(6)<\/code><\/td>\n<td>UTC\u57fa\u6e96\u3067\u65e5\u6642\u3092\u4fdd\u5b58\u3059\u308b\u5834\u5408<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>\u5b9f\u8df5\u4f8b<\/strong>\uff1a\u56fd\u5185\u5411\u3051\u306e\u696d\u52d9\u30b7\u30b9\u30c6\u30e0\u3067\u306f\u3001\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u3092\u8003\u616e\u3059\u308b\u5fc5\u8981\u304c\u306a\u3044\u5834\u5408\u304c\u591a\u3044\u305f\u3081\u3001<strong><code>LocalDateTime<\/code><\/strong>\u3068<strong><code>DATETIME(6)<\/code><\/strong>\u306e\u7d44\u307f\u5408\u308f\u305b\u304c\u6700\u3082\u63a8\u5968\u3055\u308c\u307e\u3059\u3002\n<\/p>\n<hr>\n<h2 id=\"section-4\"><strong>\u5b9f\u8df5\u4f8b\uff1a\u65e5\u6642\u60c5\u5831\u3092\u53d6\u5f97\u30fb\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3059\u308b\u5177\u4f53\u7684\u306a\u624b\u9806<\/strong><br \/><\/h2>\n<p>\n<br \/>\u3053\u3053\u3067\u306f\u3001\u5b9f\u969b\u306e\u30d6\u30ed\u30b0\u8a18\u4e8b\u4f5c\u6210\u3092\u4f8b\u306b\u3001\u65e5\u6642\u7ba1\u7406\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u3069\u3046\u6d3b\u7528\u3059\u308b\u304b\u898b\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><strong>\u76ee\u7684:<\/strong> \u8a18\u4e8b\u306e\u516c\u958b\u65e5\u6642\u3068\u66f4\u65b0\u65e5\u6642\u3092\u7ba1\u7406\u3059\u308b\u3002<br \/><strong>\u524d\u63d0\u77e5\u8b58:<\/strong> Java 17\u3001MySQL 8<\/p>\n<p><strong>\u30b9\u30c6\u30c3\u30d71\uff1a\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u30c6\u30fc\u30d6\u30eb\u306e\u4f5c\u6210<\/strong><br \/>\nMySQL\u306b\u8a18\u4e8b\u60c5\u5831\u3092\u4fdd\u5b58\u3059\u308b\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002\u516c\u958b\u65e5\u6642\u306f\u30e6\u30fc\u30b6\u30fc\u304c\u5165\u529b\u3057\u3001\u66f4\u65b0\u65e5\u6642\u306f\u30b7\u30b9\u30c6\u30e0\u304c\u81ea\u52d5\u3067\u66f4\u65b0\u3059\u308b\u3068\u3057\u307e\u3059\u3002\n<\/p>\n<pre>\n<code>\nCREATE TABLE articles (\nid INT PRIMARY KEY AUTO_INCREMENT,\ntitle VARCHAR(255) NOT NULL,\nbody TEXT,\npublished_at DATETIME(6),\nupdated_at TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP\n);\n<\/code>\n<\/pre>\n<p>\n<br \/><code>published_at<\/code>\u306b\u306f<strong><code>DATETIME(6)<\/code><\/strong>\u3092\u4f7f\u7528\u3057\u3001\u30e6\u30fc\u30b6\u30fc\u304c\u5165\u529b\u3057\u305f\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u975e\u4f9d\u5b58\u306e\u5024\u3092\u305d\u306e\u307e\u307e\u4fdd\u5b58\u3057\u307e\u3059\u3002\u4e00\u65b9\u3001<code>updated_at<\/code>\u306b\u306f**<code>TIMESTAMP(6)<\/code>**\u3092\u4f7f\u7528\u3057\u3001MySQL\u306e\u6a5f\u80fd\u3067\u81ea\u52d5\u7684\u306bUTC\u30d9\u30fc\u30b9\u3067\u66f4\u65b0\u3055\u308c\u308b\u3088\u3046\u306b\u8a2d\u5b9a\u3057\u307e\u3057\u305f\u3002<\/p>\n<p><strong>\u30b9\u30c6\u30c3\u30d72\uff1aJava\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067\u306e\u65e5\u6642\u51e6\u7406<\/strong><br \/>\n\u8a18\u4e8b\u3092\u65b0\u898f\u6295\u7a3f\u3059\u308b\u969b\u3001Java\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u65e5\u6642\u3092\u6271\u3044\u307e\u3059\u3002\n<\/p>\n<pre>\n<code>\n\/\/ \u30e6\u30fc\u30b6\u30fc\u304c\u5165\u529b\u3057\u305f\u65e5\u6642\u60c5\u5831\uff08\u4f8b: 2025-09-08T14:30\uff09\nString userPublishedDate = \"2025-09-08T14:30\";\n\/\/ MySQL\u306eDATETIME\u578b\u306b\u5bfe\u5fdc\u3059\u308bLocalDateTime\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u5909\u63db\nLocalDateTime publishedAt = LocalDateTime.parse(userPublishedDate);\n\n\/\/ \u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u4fdd\u5b58\u3059\u308b\u51e6\u7406...\n\/\/ PreparedStatement.setObject(1, publishedAt);\n<\/code>\n<\/pre>\n<p>\n<br \/>\u30e6\u30fc\u30b6\u30fc\u5165\u529b\u306e\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u3092\u6c17\u306b\u305b\u305a\u3001<strong><code>LocalDateTime<\/code><\/strong>\u3067\u305d\u306e\u307e\u307e\u6271\u3044\u307e\u3059\u3002<\/p>\n<p><strong>\u30b9\u30c6\u30c3\u30d73\uff1a\u30d6\u30ed\u30b0\u753b\u9762\u3067\u306e\u8868\u793a<\/strong><br \/>\n\u30d6\u30ed\u30b0\u306e\u8a18\u4e8b\u4e00\u89a7\u753b\u9762\u306a\u3069\u3067\u3001\u65e5\u6642\u3092\u8aad\u307f\u3084\u3059\u304f\u8868\u793a\u3057\u307e\u3059\u3002\n<\/p>\n<pre>\n<code>\n\/\/ \u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u304b\u3089\u53d6\u5f97\u3057\u305f\u65e5\u6642\u60c5\u5831\n\/\/ \u4f8b: LocalDateTime publishedAtFromDb = ...;\n\/\/ \u4f8b: Instant updatedAtFromDb = ...;\n\n\/\/ \u8868\u793a\u7528\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3092\u5b9a\u7fa9\nDateTimeFormatter dtf = DateTimeFormatter.ofPattern(\"yyyy\u5e74MM\u6708dd\u65e5 HH\u6642mm\u5206\");\n\n\/\/ LocalDateTime\u3092\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\nString displayPublishedAt = publishedAtFromDb.format(dtf);\nSystem.out.println(\"\u516c\u958b\u65e5: \" + displayPublishedAt);\n\n\/\/ Instant\u3092\u30ed\u30fc\u30ab\u30eb\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u306b\u5909\u63db\u3057\u3066\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\nString displayUpdatedAt = updatedAtFromDb.atZone(ZoneId.systemDefault()).format(dtf);\nSystem.out.println(\"\u6700\u7d42\u66f4\u65b0\u65e5: \" + displayUpdatedAt);\n<\/code>\n<\/pre>\n<p>\n<br \/>TIMESTAMP\u3067\u4fdd\u5b58\u3057\u305fInstant\u306f\u3001\u8868\u793a\u6642\u306b\u30ed\u30fc\u30ab\u30eb\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u306b\u5909\u63db\u3059\u308b\u3053\u3068\u3067\u3001\u30e6\u30fc\u30b6\u30fc\u306b\u3068\u3063\u3066\u5206\u304b\u308a\u3084\u3059\u3044\u6642\u523b\u306b\u3067\u304d\u307e\u3059\u3002\n<\/p>\n<hr>\n<h2 id=\"section-5\"><strong>\u307e\u3068\u3081\uff1a\u65e5\u6642\u7ba1\u7406\u306e\u672a\u6765\u3068\u3042\u306a\u305f\u306e\u30ad\u30e3\u30ea\u30a2<\/strong><br \/><\/h2>\n<p>\n<br \/>\u3053\u306e\u8a18\u4e8b\u3067\u306f\u3001Java\u306e\u65e5\u6642\u7ba1\u7406\u304c<strong><code>java.util.Date<\/code><\/strong>\u304b\u3089**<code>java.time<\/code>**\u3078\u3068\u3069\u306e\u3088\u3046\u306b\u5909\u9077\u3057\u3066\u304d\u305f\u304b\u3001\u305d\u3057\u3066\u6700\u65b0\u306e\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9\u3092\u89e3\u8aac\u3057\u307e\u3057\u305f\u3002<\/p>\n<p><strong>\u7d50\u5c40\u3001\u3053\u306e\u8a18\u4e8b\u3067\u4f55\u304c\u5206\u304b\u3063\u305f\u304b\uff1f<\/strong><\/p>\n<p>\u53e4\u3044API\uff08<strong><code>Date<\/code><\/strong>\/<strong><code>Calendar<\/code><\/strong>\uff09\u306f\u3001\u53ef\u5909\u6027\u3084\u76f4\u611f\u306b\u53cd\u3059\u308b\u4ed5\u69d8\u304b\u3089\u975e\u63a8\u5968\u3067\u3042\u308b\u3002<\/p>\n<p>Java 8\u4ee5\u964d\u306e**<code>java.time<\/code>** API\u306f\u3001\u4e0d\u5909\u3067\u660e\u78ba\u306a\u30af\u30e9\u30b9\u7fa4\u306b\u3088\u3063\u3066\u3001\u5b89\u5168\u3067\u6271\u3044\u3084\u3059\u3044\u65e5\u6642\u7ba1\u7406\u3092\u53ef\u80fd\u306b\u3057\u305f\u3002<\/p>\n<p>\u5b9f\u52d9\u3067\u306f\u3001LocalDateTime\u3068DATETIME\uff08\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u4e0d\u8981\uff09\u307e\u305f\u306f**Instant\u3068TIMESTAMP**\uff08UTC\u57fa\u6e96\uff09\u3092\u4f7f\u3044\u5206\u3051\u308b\u306e\u304c\u738b\u9053\u3067\u3042\u308b\u3002<\/p>\n<p>\u7cbe\u5ea6\u3092\u4fdd\u3064\u305f\u3081\u306b\u3001MySQL\u3067\u306fDATETIME(6)\u3084TIMESTAMP(6)\u3092\u4f7f\u7528\u3059\u308b\u3002<\/p>\n<p>\u65e5\u6642\u7ba1\u7406\u306f\u3001\u4e00\u898b\u5730\u5473\u306a\u30c6\u30fc\u30de\u3067\u3059\u304c\u3001\u30b7\u30b9\u30c6\u30e0\u306e\u4fe1\u983c\u6027\u306b\u76f4\u7d50\u3059\u308b\u91cd\u8981\u306a\u8981\u7d20\u3067\u3059\u3002\u3053\u306e\u77e5\u8b58\u3092\u7fd2\u5f97\u3057\u3001\u5b9f\u8df5\u3059\u308b\u3053\u3068\u3067\u3001\u3042\u306a\u305f\u306e\u958b\u767a\u8005\u3068\u3057\u3066\u306e\u5e02\u5834\u4fa1\u5024\u306f\u78ba\u5b9f\u306b\u5411\u4e0a\u3057\u307e\u3059\u3002\n<\/p>\n<hr>\n<p>\n<strong>\u3010\u3042\u306a\u305f\u306e\u6b21\u306e\u30b9\u30c6\u30c3\u30d7\u3011<\/strong><\/p>\n<p>\u3053\u306e\u77e5\u8b58\u3092\u6d3b\u304b\u3057\u3066\u3001\u3042\u306a\u305f\u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u30b3\u30fc\u30c9\u3092\u30ea\u30d5\u30a1\u30af\u30bf\u30ea\u30f3\u30b0\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><strong><a href=\"#\">\u300cJava\u3067\u5b66\u3076\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u306e\u5b8c\u5168\u30ac\u30a4\u30c9\u300d<\/a><\/strong>\uff08\u95a2\u9023\u8a18\u4e8b\u3078\u306e\u30ea\u30f3\u30af\uff09\u3082\u305c\u3072\u3054\u4e00\u8aad\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u3053\u306e\u8a18\u4e8b\u304c\u5f79\u7acb\u3063\u305f\u3068\u601d\u3063\u305f\u3089\u3001\u305c\u3072SNS\u3067\u30b7\u30a7\u30a2\u3057\u3066\u304f\u3060\u3055\u3044\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\u3001\u30d6\u30ed\u30b0\u7de8\u96c6\u9577\u306e\u4f50\u85e4\u3067\u3059\u3002\u79c1\u306f\u3053\u308c\u307e\u306720\u5e74\u4ee5\u4e0a\u30b7\u30b9\u30c6\u30e0\u958b\u767a\u306b\u643a\u308f\u3063\u3066\u304d\u305f\u73fe\u5f79\u30b7\u30b9\u30c6\u30e0\u30a8\u30f3\u30b8\u30cb\u30a2\u3067\u3042\u308a\u3001\u73fe\u5728\u306fIT\u696d\u754c\u3067\u30ad\u30e3\u30ea\u30a2\u30b3\u30f3\u30b5\u30eb\u30bf\u30f3\u30c8\u3068\u3057\u3066\u3082\u6d3b\u52d5\u3057\u3066\u3044\u307e\u3059\u3002 \u591a\u304f\u306eJava\u958b\u767a\u8005\u304c\u982d\u3092\u60a9\u307e\u305b\u308b\u554f\u984c\u306e\u4e00&hellip;<\/p>\n","protected":false},"author":1,"featured_media":339,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[12,15,14],"class_list":["post-337","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-7","tag-java","tag-localdatetime","tag-14"],"_links":{"self":[{"href":"https:\/\/i-third.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/337","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/i-third.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/i-third.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/i-third.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/i-third.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=337"}],"version-history":[{"count":1,"href":"https:\/\/i-third.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/337\/revisions"}],"predecessor-version":[{"id":338,"href":"https:\/\/i-third.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/337\/revisions\/338"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/i-third.org\/blog\/index.php?rest_route=\/wp\/v2\/media\/339"}],"wp:attachment":[{"href":"https:\/\/i-third.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=337"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/i-third.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=337"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/i-third.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=337"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}