Vision power table date picker format

on a power table when you select a date in a cell with the date picker i want to know if you can change it so it uses 24 hours (military time)

Hi Michael,

Unfortunately, the date picker format is not editable at this point. But I can see how your request would have its use cases. Feel free to submit your feature request via the Idea’s page - Ignition Features and Ideas | Inductive Automation

While doing some idle reading of older forum posts over the weekend, I ran across this cold case, and it looked interesting. With Vision, if there isn't a built in way to do something, it's usually doable with scripting.

Here is a script that will add a listener to the button that generates the datepicker, and will automatically correct the datepicker's format when the popup window is opened:

#def initialize(self):
	from java.awt import Window
	from java.awt.event import ActionListener
	from java.util import Date
	from java.text import SimpleDateFormat
	from com.jidesoft.swing import ResizableWindow
	from javax.swing import JFormattedTextField, JSpinner
	from javax.swing.plaf.synth import SynthArrowButton
	powerTable = self
	class DateEditListener(ActionListener):
	    def actionPerformed(self, actionEvent):
			def getJSpinner(window):
				for component in window.getComponents():
					if isinstance(component, JFormattedTextField) and 'JSpinner$DateEditor' in str(component.parent.__class__):
						return component.parent.spinner
					jspinner = getJSpinner(component)
					if jspinner is not None:
						return jspinner
			openDateWindows = [window for window in Window.getWindows() if isinstance(window, ResizableWindow) and window.isVisible()]
			jspinner = next((getJSpinner(window) for window in openDateWindows if getJSpinner(window) is not None), None)
			if jspinner is not None:
				format = SimpleDateFormat("HH:mm")
				newDateEditor = JSpinner.DateEditor(jspinner, format.toPattern())
				jspinner.setEditor(newDateEditor)
	for column in range(powerTable.data.columnCount):
		if powerTable.table.getColumnClass(column).isAssignableFrom(Date):
			for component in powerTable.table.columnModel.getColumn(column).getCellEditor().comboBox.getComponents():
				if isinstance(component, SynthArrowButton):
					component.addActionListener(DateEditListener())

Result:
image
This should be ran from the power table's initialize extension function. It should be noted that this extension function will not run in the designer.

1 Like