<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>chrono &#8211; カミュプリィの雑多なメモ</title>
	<atom:link href="https://www.commuply.co.jp/technic/memo/tag/chrono/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.commuply.co.jp/technic/memo</link>
	<description></description>
	<lastBuildDate>Sun, 22 Dec 2024 06:05:18 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://www.commuply.co.jp/technic/memo/wp-content/uploads/site-icon-150x150.png</url>
	<title>chrono &#8211; カミュプリィの雑多なメモ</title>
	<link>https://www.commuply.co.jp/technic/memo</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>[言語比較]今の日時</title>
		<link>https://www.commuply.co.jp/technic/memo/%e8%a8%80%e8%aa%9e%e4%bb%8a%e3%81%ae%e6%97%a5%e6%99%82/</link>
		
		<dc:creator><![CDATA[ume]]></dc:creator>
		<pubDate>Thu, 12 Dec 2024 07:54:42 +0000</pubDate>
				<category><![CDATA[未分類]]></category>
		<category><![CDATA[@Now]]></category>
		<category><![CDATA[Calendar.getInstance]]></category>
		<category><![CDATA[chrono]]></category>
		<category><![CDATA[Date]]></category>
		<category><![CDATA[Java Script]]></category>
		<category><![CDATA[Lotus Script]]></category>
		<category><![CDATA[Lotus 式言語]]></category>
		<category><![CDATA[Now]]></category>
		<category><![CDATA[time]]></category>
		<category><![CDATA[time_t]]></category>
		<category><![CDATA[[LOCALTIMEONERROR]]]></category>
		<category><![CDATA[[SERVERTIME]]]></category>
		<category><![CDATA[日時]]></category>
		<category><![CDATA[言語比較]]></category>
		<guid isPermaLink="false">https://www.commuply.co.jp/technic/memo/?p=816</guid>

					<description><![CDATA[　ほとんどの命令はコードを実行しているコンピュータの日時を返します Java Java Script Lotus Script Lotus 式言語 　コードを実行しているコンピュータの日時の他に、サーバーの日時を取得する [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>　ほとんどの命令はコードを実行しているコンピュータの日時を返します</p>


<h2 class="wp-block-heading has-base-2-background-color has-background" style="padding-top:var(--wp--preset--spacing--30);padding-right:var(--wp--preset--spacing--20);padding-bottom:var(--wp--preset--spacing--30);padding-left:var(--wp--preset--spacing--20)" id="java">Java</h2>


<pre class="wp-block-code"><code>import java.util.Calendar;
Calendar 日時値 = Calendar.getInstance();</code></pre>


<h2 class="wp-block-heading has-base-2-background-color has-background" style="padding-top:var(--wp--preset--spacing--30);padding-right:var(--wp--preset--spacing--20);padding-bottom:var(--wp--preset--spacing--30);padding-left:var(--wp--preset--spacing--20)" id="java-script">Java Script</h2>


<pre class="wp-block-code"><code>日時 = New Date();</code></pre>


<h2 class="wp-block-heading has-base-2-background-color has-background" style="padding-top:var(--wp--preset--spacing--30);padding-right:var(--wp--preset--spacing--20);padding-bottom:var(--wp--preset--spacing--30);padding-left:var(--wp--preset--spacing--20)" id="lotus-script">Lotus Script</h2>


<pre class="wp-block-code"><code>Dim 日時値 As Variant
日時値 = Now</code></pre>


<h2 class="wp-block-heading has-base-2-background-color has-background" style="padding-top:var(--wp--preset--spacing--30);padding-right:var(--wp--preset--spacing--20);padding-bottom:var(--wp--preset--spacing--30);padding-left:var(--wp--preset--spacing--20)" id="lotus-%25e5%25bc%258f%25e8%25a8%2580%25e8%25aa%259e">Lotus 式言語</h2>


<p>　コードを実行しているコンピュータの日時の他に、サーバーの日時を取得する方法が用意されています</p>



<pre class="wp-block-code"><code>日時値 = @Now
Rem {実行環境の日時を取得}</code></pre>



<pre class="wp-block-code"><code>サーバーの日時値 = @Now(&#91;SERVERTIME]:&#91;LOCALTIMEONERROR])
Rem {サーバーの日時を得られないときはクライアントの日時を取得}</code></pre>


<h2 class="wp-block-heading has-base-2-background-color has-background" style="padding-top:var(--wp--preset--spacing--30);padding-right:var(--wp--preset--spacing--20);padding-bottom:var(--wp--preset--spacing--30);padding-left:var(--wp--preset--spacing--20)" id="c">C++</h2>


<pre class="wp-block-code"><code>#include &lt;chrono&gt;
time_t 経過秒 = time(nullptr);</code></pre>



<p>　くわしくはこちらの記事に記載しています↓</p>



<style>
.simpleblogcard_img_block28f559fa60345d2e5e8ba4dbff289754 {
  float: left;
  padding: 10px;
}
.simpleblogcard_border28f559fa60345d2e5e8ba4dbff289754 {
  border-right: solid 5px #7db4e6;
  padding: 0.25em 0.25em;
  background: transparent;
}
.simpleblogcard_title28f559fa60345d2e5e8ba4dbff289754 {
  line-height: 120%;
  font-weight: bold;
  display: block;
}
.simpleblogcard_description28f559fa60345d2e5e8ba4dbff289754 {
  line-height: 120%;
  color: #333;
}
</style>
<div class="simpleblogcard_wrap">
			<a style="text-decoration: none;" href=https://www.commuply.co.jp/technic/memo/get-now/ target="_blank" rel="noopener">
				<figure class="simpleblogcard_img_block28f559fa60345d2e5e8ba4dbff289754">
			<img decoding="async" style="border-radius: 5px; width: 96px; height: 96px;" src="https://www.commuply.co.jp/technic/memo/wp-content/uploads/site-icon.png" alt="[C++]今の日時を取得" />
		</figure>
		<div class="simpleblogcard_inner">
		<div class="simpleblogcard_border28f559fa60345d2e5e8ba4dbff289754">
						<div class="simpleblogcard_title28f559fa60345d2e5e8ba4dbff289754">
				[C++]今の日時を取得			</div>
							<div class="simpleblogcard_description28f559fa60345d2e5e8ba4dbff289754">
					はじめに 　今の日付と時刻を知りたいとおもったことはありませんか。いくつか方法を記載します。　ユーザー定義の変数名は日本語にしています。メリハリがあるとコードが読みやすいかなぁとおもったので。　サンプ&#8230;				</div>
					</div>
	</div>
	<div style="clear: both;"></div>
	</a>
</div>



<p></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[C++]今の日時を取得</title>
		<link>https://www.commuply.co.jp/technic/memo/get-now/</link>
		
		<dc:creator><![CDATA[ume]]></dc:creator>
		<pubDate>Fri, 25 Mar 2022 14:10:29 +0000</pubDate>
				<category><![CDATA[未分類]]></category>
		<category><![CDATA[2038年問題]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Char]]></category>
		<category><![CDATA[chrono]]></category>
		<category><![CDATA[GMT]]></category>
		<category><![CDATA[gmtime_s]]></category>
		<category><![CDATA[L]]></category>
		<category><![CDATA[localtime_s]]></category>
		<category><![CDATA[Now]]></category>
		<category><![CDATA[null]]></category>
		<category><![CDATA[nullptr]]></category>
		<category><![CDATA[sizeof]]></category>
		<category><![CDATA[strftime]]></category>
		<category><![CDATA[time]]></category>
		<category><![CDATA[time_point]]></category>
		<category><![CDATA[time_t]]></category>
		<category><![CDATA[to_time_t]]></category>
		<category><![CDATA[using namespace std]]></category>
		<category><![CDATA[UTC]]></category>
		<category><![CDATA[wchar_t]]></category>
		<category><![CDATA[wcsftime]]></category>
		<category><![CDATA[ローカルタイム]]></category>
		<category><![CDATA[今の日時]]></category>
		<category><![CDATA[協定世界時]]></category>
		<category><![CDATA[年/月/日]]></category>
		<category><![CDATA[日/月/年]]></category>
		<category><![CDATA[日付の並び順]]></category>
		<category><![CDATA[日時]]></category>
		<category><![CDATA[月/日/年]]></category>
		<category><![CDATA[現地時間]]></category>
		<category><![CDATA[経過秒]]></category>
		<guid isPermaLink="false">https://www.commuply.co.jp/technic/notesdomino/?p=167</guid>

					<description><![CDATA[はじめに 　今の日付と時刻を知りたいとおもったことはありませんか。いくつか方法を記載します。　ユーザー定義の変数名は日本語にしています。メリハリがあるとコードが読みやすいかなぁとおもったので。　サンプルでは『using  [&#8230;]]]></description>
										<content:encoded><![CDATA[<h2 class="wp-block-heading" id="%25e3%2581%25af%25e3%2581%2598%25e3%2582%2581%25e3%2581%25ab">はじめに</h2>


<p>　今の日付と時刻を知りたいとおもったことはありませんか。いくつか方法を記載します。<br>　ユーザー定義の変数名は日本語にしています。メリハリがあるとコードが読みやすいかなぁとおもったので。<br>　サンプルでは『using namespace std;』を省略していますので、コードを試すときはこの行をおぎなってください。</p>


<h2 class="wp-block-heading" id="%25e7%25b5%258c%25e9%2581%258e%25e7%25a7%2592%25e3%2582%2592-timet-%25e5%25bd%25a2%25e5%25bc%258f%25e3%2581%25a7%25e5%258f%2596%25e5%25be%2597">『<strong>経過秒</strong>』を time_t 形式で取得</h2>


<p>　とりあえず time_t 形式にします。これは『1970/01/01 00:00:00 UTC からの<strong>経過秒</strong>』です。<br>　32ビットシステムでは 2038/01/19 03:14:07 まで表現できるそうです。もうすぐトラブルが発生しそうな予感がしますね。64ビットシステムへの移行が必要です。</p>


<h3 class="wp-block-heading" id="now%25e3%2582%2592%25e4%25bd%25bf%25e3%2581%2586%25e6%2596%25b9%25e6%25b3%2595">now()を使う方法</h3>


<pre class="wp-block-preformatted">#include &lt;chrono&gt;
chrono::system_clock::time_point 日時 = chrono::system_clock::<strong>now()</strong>;
time_t <strong>経過秒</strong> = chrono::system_clock::to_time_t(日時);</pre>


<h3 class="wp-block-heading" id="timenullptr%25e3%2582%2592%25e4%25bd%25bf%25e3%2581%2586%25e6%2596%25b9%25e6%25b3%2595">time(nullptr)を使う方法</h3>


<pre class="wp-block-preformatted">#include &lt;chrono&gt;
time_t <strong>経過秒</strong> = time(nullptr);</pre>



<p>　『nullptr』を使うことが推奨されているようですが、かわりに『NULL』や『0』を使うこともできます。</p>


<h2 class="wp-block-heading" id="%25e6%25a7%258b%25e9%2580%25a0%25e4%25bd%2593-tm-%25e5%25bd%25a2%25e5%25bc%258f%25e3%2581%25b8%25e5%25a4%2589%25e6%258f%259b">構造体 tm 形式へ変換</h2>


<p>　先ほど求めた<strong>経過秒</strong>（time_t）を<strong>今の日時</strong> (struct tm) にします。<strong>今の日時</strong>といっても色々ありますが、協定世界時 (UTC,GMT) へ変換するものと、現地時間（ローカルタイム）へ変換するものを記載します。</p>


<h3 class="wp-block-heading" id="%25e5%258d%2594%25e5%25ae%259a%25e4%25b8%2596%25e7%2595%258c%25e6%2599%2582%25e3%2581%25b8">協定世界時へ</h3>


<pre class="wp-block-preformatted">struct tm <strong>今の日時</strong>;
gmtime_s(&amp;<strong>今の日時</strong>, &amp;<strong>経過秒</strong>);</pre>


<h3 class="wp-block-heading" id="%25e7%258f%25be%25e5%259c%25b0%25e6%2599%2582%25e9%2596%2593%25e6%2597%25a5%25e6%259c%25ac%25e6%2599%2582%25e9%2596%2593%25e3%2581%25b8">現地時間（日本時間）へ</h3>


<pre class="wp-block-preformatted">struct tm <strong>今の日時</strong>;
localtime_s(&amp;<strong>今の日時</strong>, &amp;<strong>経過秒</strong>);</pre>


<h2 class="wp-block-heading" id="%25e4%25bb%258a%25e3%2581%25ae%25e6%2597%25a5%25e6%2599%2582-struct-tm-%25e3%2582%2592%25e6%2596%2587%25e5%25ad%2597%25e3%2581%25ae%25e6%2597%25a5%25e6%2599%2582-char%25e3%2581%25b8"><strong>今の日時</strong> (struct tm) を文字<strong>の日時</strong> (char[])へ</h2>


<p>　<strong>今の日時</strong>を文字として整形してみましょう。日付の文字列は国によって異なりますが、今回は日本の形式にします。<br>　・日本 : <strong>年</strong>/<span class="bold-red">月</span>/日<br>　・イギリス : 日/<strong><span class="bold-red">月</span></strong>/<strong>年</strong><br>　・アメリカ : <span class="bold-red">月</span>/日/<strong>年</strong><br>　国によって日付の並び順が異なりますが、何だか話す順番に通じるものがあるような気がします。</p>


<h3 class="wp-block-heading" id="char%25e5%259e%258b%25e3%2581%25ae%25e5%25b9%25b4%25e6%259c%2588%25e6%2597%25a5-%25e6%2599%2582%25e5%2588%2586%25e7%25a7%2592%25e3%2581%25b8">char型の『年/月/日 時:分:秒』へ</h3>


<pre class="wp-block-preformatted">char <strong>文字の日時</strong>[128];
strftime(<strong>文字の日時</strong>, 128, "%Y/%m/%d %H:%M:%S", &amp;<strong>今の日時</strong>);</pre>



<p>　char[128] では sizeof(char[128]) が128になります。strftime(<strong>文字の日時</strong>, <span class="bold-red">sizeof(<strong>文字の日時</strong>)</span>, &#8230; としても大丈夫そうです。</p>


<h3 class="wp-block-heading" id="wchart%25e5%259e%258b%25e3%2581%25ae%25e5%25b9%25b4%25e6%259c%2588%25e6%2597%25a5-%25e6%2599%2582%25e5%2588%2586%25e7%25a7%2592%25e3%2581%25b8">wchar_t型の『年/月/日 時:分:秒』へ</h3>


<pre class="wp-block-preformatted">wchar_t <strong>文字の日時</strong>[128];
wcsftime(<strong>文字の日時</strong>, 128, L"%Y/%m/%d %H:%M:%S", &amp;<strong>今の日時</strong>);</pre>



<p>　wchar_t[128] では sizeof(wchar_t[128]) が 256 になります。wcsftime(<strong>文字の日時</strong>, <span class="bold-red">sizeof(<strong>文字の日時</strong>)</span>, &#8230; とはできませんね。</p>


<h2 class="wp-block-heading" id="%25e3%2581%2595%25e3%2581%2584%25e3%2581%2594%25e3%2581%25ab">さいごに</h2>


<p>　コード全体を書いてみましょう。</p>



<pre class="wp-block-preformatted">#include &lt;chrono&gt;
using namespace std;
time_t <strong>経過秒</strong> = time(nullptr);
struct tm <strong>今の日時</strong>;
localtime_s(&amp;<strong>今の日時</strong>, &amp;<strong>経過秒</strong>);
char <strong>文字の日時</strong>[128];
strftime(<strong>文字の日時</strong>, 128, "%Y/%m/%d %H:%M:%S", &amp;<strong>今の日時</strong>);
cout &lt;&lt; "今は " &lt;&lt; <strong>文字の日時</strong> &lt;&lt; endl;
</pre>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
