adb shell date now


I don’t like iOS but I hate Android.

References

$

... $ adb shell date -s `date +"%Y%m%d.%H%M%S"`

>

PS ...> adb shell date -s $(get-date -format yyyyMMdd.HHmmss)

public class AdbShellDateNow {

    public static void main(final String[] args)
        throws java.io.IOException, InterruptedException {

        final long now = System.currentTimeMillis() / 1000L;
        final ProcessBuilder builder =
            new ProcessBuilder("adb", "shell", "date", Long.toString(now));
        builder.redirectErrorStream(true);
        builder.redirectOutput(ProcessBuilder.Redirect.INHERIT);

        final Process process = builder.start();
        process.waitFor();
    }
}
Advertisements

One comment

  1. yuda

    Thank you,I love the AdbShellDateNow java class,
    i add to this :
    public static void main(final String[] args) {
    String format = “YYYYMMdd.HHmmss”;
    SimpleDateFormat dateFormatYouWant = new SimpleDateFormat(format);
    String currentTimeAsString = dateFormatYouWant.format(new Date());

        final ProcessBuilder builder = new ProcessBuilder("adb", "shell", "date", currentTimeAsString);
        builder.redirectErrorStream(true);
        builder.redirectOutput(ProcessBuilder.Redirect.INHERIT);
    
        final Process process = builder.start();
        process.waitFor();
    }
    

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s