Skip to content

Instantly share code, notes, and snippets.

@daler445
Last active July 1, 2018 07:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daler445/8e8161098d73d87d982bc1b82624a46b to your computer and use it in GitHub Desktop.
Save daler445/8e8161098d73d87d982bc1b82624a46b to your computer and use it in GitHub Desktop.
изменение даты на java / date changing
String dateString = null;
String dtStart = "2018-06-23T16:52:13"; // before/до
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.ENGLISH); // pattern/шаблон English locale/Английская локализация
try {
Date c_date = format.parse(dtStart);
Long newDate = c_date.getTime() + 18000000; // add 5 hours in ms / добавить 5 часов в мс --> (GMT+5)
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm dd MMMM, yyyy", new Locale("ru")); // new pattern/новый шаблон new Russian locale/новая русская локализация
dateString = formatter.format(new Date(newDate));
} catch(ParseException e) {
e.printStackTrace();
}
dateString // result/результат
// output/вывод: 16:52 23 Июнь, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment