Skip to content

Instantly share code, notes, and snippets.

@gizemabali
Created March 11, 2019 13:57
Show Gist options
  • Save gizemabali/82ae75d8abd09dd785ba101947ce4620 to your computer and use it in GitHub Desktop.
Save gizemabali/82ae75d8abd09dd785ba101947ce4620 to your computer and use it in GitHub Desktop.
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
String strDate = "2019-04-01T00:00";
// create format
SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");
DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC"));
// parse date
Date date = DATE_FORMAT.parse(strDate);
// set date to calendar
Calendar cal = Calendar.getInstance();
cal.setTimeZone(TimeZone.getTimeZone("UTC"));
cal.setTime(date);
// create str date from calendar
String newDateStart = DATE_FORMAT.format(cal.getTime());
// prints:
// 2017-01-01T00:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment