![]() Output from this snippet is: Time in New York: T01:00-04:00 ZonedDateTime nyTime = LocalDateTime.parse(input, formatter) = DateTimeFormatter.ofPattern("uuuu-MM-dd HH:mm:ss") Second message, use java.time, the modern Java date and time API, for your date and time work. In those cases parse into a proper date-time object first thing. It may be from a text file, from the user or from data exchange with another system, for example. ![]() Sometimes we get date and time as string input. Just as you don’t handle numbers and Boolean values as strings (I hope). ("The date and time in :: "+ obj.getDisplayName() + "is ::" + theResult) įirst message, don’t handle your date and time as strings in your code. ![]() ("The current time in India is :: " +currentdate.getTime()) (formatter.parse(strdate)) ĭate theResult = formatter.parse(strdate) TimeZone obj = TimeZone.getTimeZone("CST") Strdate = formatter.format(currentdate.getTime()) The code is :: package MyPackage Ĭalendar currentdate = Calendar.getInstance() ĭateFormat formatter = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss") The date and time in :: Central Standard Time is :: Sat Feb 25 03:39:Īnd the actual Time according to CST time zone is :: Friday, 24 February 4:39:16 a.m(GMT - 6:00) The current time in India is :: Fri Feb 24 16:09: Like if i execute my program at a particular time. ![]() I am not getting any error but i am not getting my output as expected. I have written this code to convert the current system date and time to some other timezone. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |