Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
odakyuToiletSignage
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
kddi
odakyuToiletSignage
Commits
35a6c1c4
Commit
35a6c1c4
authored
Jan 25, 2018
by
leej
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#28062 NTPサーバのタイムスタンプJSON型のURLに変更
parent
4073ea50
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
18 deletions
+10
-18
app/src/main/java/jp/odakyu/toiletsignage/connection/NtpServerConnection.java
+2
-4
app/src/main/java/jp/odakyu/toiletsignage/task/UpdateToiletInfoTask.java
+8
-6
app/src/main/java/jp/odakyu/toiletsignage/util/DateTimeUtil.java
+0
-8
No files found.
app/src/main/java/jp/odakyu/toiletsignage/connection/NtpServerConnection.java
View file @
35a6c1c4
...
...
@@ -14,7 +14,7 @@ import java.net.URL;
*/
public
class
NtpServerConnection
{
private
static
final
String
NTP_SERVER_URL
=
"http://ntp-a1.nict.go.jp/cgi-bin/
ntp
"
;
private
static
final
String
NTP_SERVER_URL
=
"http://ntp-a1.nict.go.jp/cgi-bin/
json
"
;
private
static
final
int
CONNECTION_TIMEOUT
=
5
*
1000
;
private
static
final
int
READ_TIMEOUT
=
5
*
1000
;
...
...
@@ -44,9 +44,7 @@ public class NtpServerConnection {
bufferedReader
=
new
BufferedReader
(
inReader
);
String
line
;
while
((
line
=
bufferedReader
.
readLine
())
!=
null
)
{
if
(
line
.
indexOf
(
"<"
)
==
-
1
&&
line
.
indexOf
(
">"
)
==
-
1
)
{
result
.
append
(
line
);
}
result
.
append
(
line
);
}
return
result
.
toString
();
}
...
...
app/src/main/java/jp/odakyu/toiletsignage/task/UpdateToiletInfoTask.java
View file @
35a6c1c4
...
...
@@ -12,6 +12,8 @@ import java.io.DataOutputStream;
import
java.io.IOException
;
import
android.content.pm.PackageManager
;
import
android.content.pm.PackageManager.NameNotFoundException
;
import
java.sql.Timestamp
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.TimerTask
;
...
...
@@ -128,14 +130,14 @@ public class UpdateToiletInfoTask extends TimerTask {
* NTPサーバーの時刻を取得し、端末時刻にセット
* @throws IOException
*/
private
void
synchronizingNtpServerDate
()
throws
IOException
{
private
void
synchronizingNtpServerDate
()
throws
IOException
,
JSONException
{
if
(
isAbnormalYear
())
{
String
result
=
NtpServerConnection
.
connectionNtpServer
();
Logger
.
d
(
TAG
,
"NTP Server Time : "
+
result
);
String
jsonString
=
NtpServerConnection
.
connectionNtpServer
();
JSONObject
jsonObject
=
new
JSONObject
(
jsonString
);
Long
ntpTimeMillis
=
(
long
)
((
Double
)
jsonObject
.
get
(
"st"
)
*
1000
);
Logger
.
d
(
TAG
,
"NTP Server ntpTimeMillis : "
+
ntpTimeMillis
);
//ntpサーバから取得時間の結果が秒(xxxxxxxxxx.xxx)なのでミリ秒に変換のため、小数点を削除
String
ntpTimeMillis
=
result
.
replace
(
"."
,
""
);
String
cmd
=
"date "
+
DateTimeUtil
.
convertNtpTimeToStringTime
(
Long
.
parseLong
(
ntpTimeMillis
),
DateTimeFormat
.
MMDDHHmmyyyyss__colon
);
String
cmd
=
"date "
+
DateTimeUtil
.
toString
(
new
Timestamp
(
ntpTimeMillis
),
DateTimeFormat
.
MMDDHHmmyyyyss__colon
);
Logger
.
d
(
TAG
,
"Command : "
+
cmd
);
runAsRoot
(
cmd
);
}
...
...
app/src/main/java/jp/odakyu/toiletsignage/util/DateTimeUtil.java
View file @
35a6c1c4
...
...
@@ -538,12 +538,4 @@ public class DateTimeUtil {
df
.
setTimeZone
(
TimeZone
.
getTimeZone
(
"GMT"
));
return
df
.
format
(
date
)+
" GMT"
;
}
public
static
String
convertNtpTimeToStringTime
(
long
ntpTime
,
String
format
)
{
//NTP時刻(基準年度:1900年)とUTC時刻(基準年度:1970年)のオフセット(ミリ秒)
long
offset
=
(
long
)
25567
*
24
*
60
*
60
*
1000
;
long
result
=
ntpTime
-
offset
;
return
new
SimpleDateFormat
(
format
).
format
(
new
Timestamp
(
result
));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment