From 9192c600889f0b7d402405cc8c870512b8fac3c0 Mon Sep 17 00:00:00 2001 From: Kieran Coldron Date: Sun, 26 Aug 2018 00:13:32 +0100 Subject: [PATCH] Add date format option (#203) --- .../main/java/com/termux/api/DialogActivity.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/src/main/java/com/termux/api/DialogActivity.java b/app/src/main/java/com/termux/api/DialogActivity.java index 5c91122..477fe03 100644 --- a/app/src/main/java/com/termux/api/DialogActivity.java +++ b/app/src/main/java/com/termux/api/DialogActivity.java @@ -45,6 +45,7 @@ import com.termux.api.util.ResultReturner; import com.termux.api.util.TermuxApiLogger; import com.termux.api.util.TermuxApiPermissionActivity; +import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.List; import java.util.Locale; @@ -419,6 +420,18 @@ public class DialogActivity extends AppCompatActivity { Calendar calendar = Calendar.getInstance(); calendar.set(year, month, day, 0, 0, 0); + final Intent intent = activity.getIntent(); + if (intent.hasExtra("date_format")) { + String date_format = intent.getStringExtra("date_format"); + try { + SimpleDateFormat dateFormat = new SimpleDateFormat(date_format); + dateFormat.setTimeZone(calendar.getTimeZone()); + return dateFormat.format(calendar.getTime()); + } catch (Exception e) { + inputResult.error = e.toString(); + postCanceledResult(); + } + } return calendar.getTime().toString(); }