Time conversion to 24hr format
						
					
					
				
			
		
	
			
	
	
	
	
	
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
‎08-28-2020 07:15 AM
Hi,
I was asked to write a script to convert CST time to GMT time. I developed that successfully but now i am asked to convert 12 hour format to 24 hour format in same script. Can you please suggest what changes i can do to achieve this in below script.
var tz = Packages.java.util.TimeZone.getTimeZone("GMT");
 
 var sd = new GlideDateTime();
 sd.setTZ(tz);
 sd.setValue(current.start_date);
 variable.inputs.planned_start_date = sd.getDisplayValue().toString();
 
 var ed = new GlideDateTime();
 ed.setTZ(tz);
 ed.setValue(current.end_date);
 variable.inputs.planned_end_date = ed.getDisplayValue().toString();
 
ServiceNow Community Rising Star 2022/2023
- Labels:
 - 
						
							
		
			Scripting and Coding
 
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
‎08-28-2020 04:08 PM
Please use class- java.text.SimpleDateFormat
The format string consists of the following abbreviations.
| Field | Full form | Short form | 
|---|---|---|
| Hour (1-12) | hh (2 digits) | h (1 or 2 digits) | 
| Hour (0-23) | HH (2 digits) | H (1 or 2 digits) | 
| Minute | mm (2 digits) | m (1 or 2 digits) | 
| Second | ss (2 digits) | s (1 or 2 digits) | 
https://docs.servicenow.com/bundle/geneva-servicenow-platform/page/administer/time/reference/r_TimeFormat.html
Please like or comment if helpful or accept solution.
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
‎09-09-2020 12:43 PM
Can you please accept the solution if this helps ? This would inturn help others with similar questions.Thanks
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
‎08-28-2020 11:40 PM
Try script below:
var tz = Packages.java.util.TimeZone.getTimeZone("GMT");
var sd = new GlideDateTime();
sd.setTZ(tz);
sd.setValue(current.start_date);
var sdDate = sd.getLocalDate();
var sdTime = sd.getLocalTime();
variable.inputs.planned_start_date =sdDate + " " + sdTime.getFormat("HH:mm:ss");
var ed = new GlideDateTime();
ed.setTZ(tz);
ed.setValue(current.end_date);
var edDate = sd.getLocalDate();
var edTime = sd.getLocalTime();
variable.inputs.planned_end_date = edDate + " " + edTime.getFormat("HH:mm:ss");
					
				
			
			
				
			
			
				
			
			
			
			
			
			
		- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
‎09-13-2020 11:09 PM
Hozawa Hi,
This script didn't work.
ServiceNow Community Rising Star 2022/2023
