Set Toast Appear Length

I found a solution to this by calling toast.cancel() after a certain delay that is shorter than the standard toast duration. final Toast toast = Toast.makeText(ctx, “This message will disappear in 1 second”, Toast.LENGTH_SHORT); toast.show(); Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { toast.cancel(); } }, 1000);

Run code for x seconds in Java?

The design of this depends on what you want doing for 15s. The two most plausible cases are “do this every X for 15s” or “wait for X to happen or 15s whichever comes sooner”, which will lead to very different code. Just waiting Thread.sleep(15000) This doesn’t iterate, but if you want to do nothing … Read more

Convert UTC to “local” time in Go

Keep in mind that the playground has the time set to 2009-11-10 23:00:00 +0000 UTC, so it is working. The proper way is to use time.LoadLocation though, here’s an example: var countryTz = map[string]string{ “Hungary”: “Europe/Budapest”, “Egypt”: “Africa/Cairo”, } func timeIn(name string) time.Time { loc, err := time.LoadLocation(countryTz[name]) if err != nil { panic(err) } … Read more

Mysql Average on time column?

Try this: SELECT SEC_TO_TIME(AVG(TIME_TO_SEC(`login`))) FROM Table1; Test data: CREATE TABLE `login` (duration TIME NOT NULL); INSERT INTO `login` (duration) VALUES (’00:00:20′), (’00:01:10′), (’00:20:15′), (’00:06:50′); Result: 00:07:09

How do I convert a date/time to epoch time (unix time/seconds since 1970) in Perl?

If you’re using the DateTime module, you can call the epoch() method on a DateTime object, since that’s what you think of as unix time. Using DateTimes allows you to convert fairly easily from epoch, to date objects. Alternativly, localtime and gmtime will convert an epoch into an array containing day month and year, and … Read more

Getting Date in HTTP format in Java

java.time EDIT: DateTimeFormatter.ofPattern(“EEE, dd MMM yyyy HH:mm:ss z”, Locale.ENGLISH).withZone(ZoneId.of(“GMT”)) is the way to do it with pure java.time. HTTP 1.1 is to not a 100% match with RFC 1123, so using the java.time.format.DateTimeFormatter.RFC_1123_DATE_TIME formatter will fail for day-of-month less than 10. (thanks to @PavanKamar and @ankon for pointing that out) Note: to be backwards compliant, … Read more

How to convert time to ” time ago ” in android

I see mainly three ways: a) built-in options using SimpleDateFormat and DateUtils SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd’T’HH:mm:ss.SSS’Z'”); sdf.setTimeZone(TimeZone.getTimeZone(“GMT”)); try { long time = sdf.parse(“2016-01-24T16:00:00.000Z”).getTime(); long now = System.currentTimeMillis(); CharSequence ago = DateUtils.getRelativeTimeSpanString(time, now, DateUtils.MINUTE_IN_MILLIS); } catch (ParseException e) { e.printStackTrace(); } b) external library ocpsoft/PrettyTime (based on java.util.Date) Here you have to use SimpleDateFormat, too, … Read more