Format Date Time using the user's format

Posted by IramK on 08-Jul-2015 07:22

Hello,

I have a date time field and I would like to set its value based on the user's date time format set in the localization settings. So say if the date time format was like: dd/MM/yyyy, HH:mm. How can I use the Rollbase function to set a date time field according to this format?

Issues:

1) I can obviously use rbf_formatDate() to set the date but what about time?

2) The date time format can change based on the user, so its not necessary that it will be the same format given above. Is there a way that I could use the rbf_formatDate function such that it would allow me to cater for all situations?

Kindly let me know.

Cheers.

IK

Posted by Gian Torralba on 13-Jul-2015 10:40

Hello,

For now, you can use client-side javascript code to create custom conditions that will check the current user's date/time format and set the date/time of your field by using Javascript's date functions.

Regards,

Gian

All Replies

Posted by Manooj Murali on 08-Jul-2015 10:47

At the moment, there is no Rollbase function to achieve this. rbf_formatDate can handle only a predefined set of date formats and will not work for the comprehensive localization formats.

Posted by Manooj Murali on 09-Jul-2015 06:58

Update : I think we are fixing some issues in 4.0 which would enable rb_formatDate to leverage the Kendo culture.

Posted by Mohammed Siraj on 10-Jul-2015 02:24

Yes, as indicated by Manooj above, in the forthcoming release, we will have client side JS  functions to access display format patterns from a User's localization settings.

This can then be used in conjunction with rbf_formatDate to generate date & date-time literal strings.

Also, to set Date & Date-Time field values in Object Record New/Edit pages, setting Date objects should suffice.

Posted by Gian Torralba on 13-Jul-2015 10:40

Hello,

For now, you can use client-side javascript code to create custom conditions that will check the current user's date/time format and set the date/time of your field by using Javascript's date functions.

Regards,

Gian

Posted by Mohammed Siraj on 16-Sep-2015 12:13

As discussed earlier, in New UI, to read display formats from Users localization settings, on client side, review the following snippet:

<script>

var rbf_getPageContext = function(){

  return rbf_isNewUI() ? rb.newui.page.PageContext : null;

};

try{

var pageContext = rbf_getPageContext ();

if(!Boolean(pageContext)){

 throw "This script component is written specific to New UI Context.";

}

var locContext = pageContext .getPageLocalization();

rb.newui.util.logToConsole('Date format pattern -'+locContext.getDateFormat());

rb.newui.util.logToConsole('Date format (long) pattern -'+locContext.getLongDateFormat());

//how to format a date as per user's localization settings

rb.newui.util.logToConsole('Current date formatted as per users localization settings -'+

rbf_formatDate(new Date(),locContext.getLongDateFormat()));

//similarly for other formats

}

catch(err){

if(console){

console.log('Error executing script component in page. '+err);

}

}

</script>

This thread is closed