android - How to validate Unix Timestamp in Java? -
i have android application stores unix timestamp of event in shared preferences. since files can accessed (and modified) has rooted phone, i'm applying validation check in app before processing value. so, question is, how can unix timestamp validated?
for example
string timestamp = "1415251687"; validateunixtime(timestamp);
should homecoming true
and
timestamp = "1415-dummydata"; validateunixtime(timestamp);
should homecoming false
edit: clear, i'm storing (and fetching) value of timestamp long
shared preferences. code above sake of simplicity. function should take long
parameter, validate it, , homecoming true
or false
based on beingness valid unix timestamp value.
this depends on when want timestamp considered invalid. next code (that got another answer) might help main idea.
public static final string release_date = "2011/06/17"; private static final long min_timestamp; static { seek { min_timestamp = new simpledateformat("yyyy-mm-dd").parse(release_date).gettime(); } grab (parseexception e) { throw new assertionerror(e); } } // after software release , not in future. public static final boolean validtimestamp(long ts) { homecoming ts >= min_timestamp && ts <= system.currenttimemillis(); }
android
No comments:
Post a Comment