Created
March 11, 2019 13:57
-
-
Save gizemabali/82ae75d8abd09dd785ba101947ce4620 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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