I used the following code to convert a string to a date, but applies the device time zone when converting.I do not need this, but I need the same date / time from this line as
String = "2009-07-31 07:59:17.427" Date = 2009-07-31 07:59:17.427 Date formatter = new Date(HttpDateParser.parse("2009-07-31 07:59:17.427")); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); String strCustomDateTime = dateFormat.format(formatter);
You can accept the default timezone offset that you received after parsing:
public static String StringToDate(String dateToParse) { Date formatter = new Date(HttpDateParser.parse(dateToParse)); SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss.SSS"); int offset = TimeZone.getDefault().getRawOffset(); formatter.setTime(formatter.getTime() + offset); String strCustomDateTime = dateFormat.format(formatter); return strCustomDateTime; }
, ? "2009-07-31 07: 59: 17.427" , - . , , , .
, , DateFormat.setTimeZone():
format.setTimeZone(TimeZone.getTimeZone("your time zone"));
Source: https://habr.com/ru/post/1714039/More articles:Massive data processing using JavaScript chart library - javascriptСтранный стандарт для файлов FAT32> 4gb - filesystemsKeep original value in DataBase when NULL passed to stored procedure - sqlMultiple WebClients, weclints stop working over time - c #Why does my Visual Studio 2008 close every time I open a .xaml file? - visual-studioStoring passwords for batch jobs - javaBringing Power to PHP - mathLimiting login attempts regardless of user? - securityWhat is the python equivalent of "urllib2" on a point network? - c #How to disable toolbar in VisualStudio 2008 - visual-studioAll Articles