How to get CST time ?

0
I have a requirement to get the current CST time. Please advise on how to get it.
asked
5 answers
1

Important question first is; when do you need the CST time? 

If it is related to user context; page/microflow, then '[%CurrentDateTime%]' is in the Users Time zone.

Which means that when a user has the CST Timezone set, than it already works. 

Or if the user hasn't set his Timezone, then the application default is used (project settings) 

Above included Daylight savings time

answered
0

To set your time zone goto settings Default time zone.

 

Regards,

Ronald

[EDIT]

I always use a small piece of Java code to check DST:
 

// This file was generated by Mendix Modeler.
//
// WARNING: Only the following code will be retained when actions are regenerated:
// - the import list
// - the code between BEGIN USER CODE and END USER CODE
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
// Other code you write will be lost the next time you deploy the project.
// Special characters, e.g., é, ö, à, etc. are supported in comments.

package basis.actions;

import com.mendix.systemwideinterfaces.core.UserAction;
import java.util.TimeZone;
import com.mendix.systemwideinterfaces.core.IContext;
import com.mendix.webui.CustomJavaAction;

/**
 * Check if a time zone has DST active. Input is string with timezone like CET and a Date.
 */
public class DSTCheck extends CustomJavaAction<Boolean>
{
	private String timeZoneString;
	private java.util.Date inputDate;

	public DSTCheck(IContext context, String timeZoneString, java.util.Date inputDate)
	{
		super(context);
		this.timeZoneString = timeZoneString;
		this.inputDate = inputDate;
	}

	@Override
	public Boolean executeAction() throws Exception
	{
		// BEGIN USER CODE
	    TimeZone tz = TimeZone.getTimeZone(timeZoneString);
	    return tz.inDaylightTime(inputDate);

		// END USER CODE
	}

	/**
	 * Returns a string representation of this action
	 */
	@Override
	public String toString()
	{
		return "DSTCheck";
	}

	// BEGIN EXTRA CODE
	// END EXTRA CODE
}

 

answered
3

Hi Vinod,

You can use the current date time token and use the addhours function to get CST time. The current date time token is in UTC, so you would just have to add the offset for CST.

 

here is an example. 

addHours([%CurrentDateTime%], -6)

 

Another option would to get the offset from the system module. There is a table called "TimeZone" that stores all of the offsets. You could find out what the code is for CST, retrieve the CST timezone object, and use the offset attribute when calculating current CST time. 

 

Hope this helps!

answered
0

Hi Vinod, 

Like we spoke about yesterday, I think the correct way to handle this would be to have a split in your validation flow that checks if it's daylight savings time of not (based on the day of the year) and then either applies a -6 or -5 offset to the UTC time. 

answered
-1

The offset is incorrect in System.TimeZone. Its is -6. However this is day light savings time and the actual offset should have been -5. So I cannot use this for calculation.

answered