Skip to main content
pshashipreetham
18-Opal
18-Opal
August 19, 2021
Solved

Date Format issue, while converting string to DateTime

  • August 19, 2021
  • 1 reply
  • 3062 views

I want the time stamp in the following format "HH:mm:ss dd/MM/yyyy", but the output is the default one, but when I use following code, the output of the code has Date First and Time next

 

 

//DateTime Format I wanted
var sdf = "HH:mm:ss dd/MM/yyyy";

// dateValue:DATETIME
var dateValue = new Date();

// dateFormat(dateValue:DATETIME,dateFormat:STRING):STRING
var formattedDate = dateFormat(dateValue, sdf);

// parseDate(stringDate:STRING,dateFormat:STRING):DATETIME
var result = parseDate(formattedDate, "HH:mm:ss dd/MM/yyyy");

But the Outout is from parseDate is 2021-08-19 13:37:32.000 instead of 13:37:32 2021-08-19

 


@paic  @slangley  @c_lowy  @CarlesColl 

Thanks,

Shahsi !!

Best answer by bchaudhary_448008

Hello @pshashipreetham ,

If you are planning to display the same date format(dd/mm/yyyy instead of yyyy/mm/dd) using Grid than it can be done using Localization Tokens defined in the Default Localization table. 

Regards

Bhawna

1 reply

5-Regular Member
August 19, 2021

Hi @pshashipreetham ,

 

For converting from String to DateTime format in ThingWorx, use below line of code:

parseDate(DateInString,"yyyy-MM-dd HH:mm:ss.SSS");

 

Kindly revert if this works for you!

 

Bhawna

pshashipreetham
18-Opal
18-Opal
August 19, 2021

Hi @bchaudhary_448008 ,

Thanks for the quick response, Please Read the post again, I need the output in this format only:

var result = parseDate(formattedDate, "HH:mm:ss dd/MM/yyyy");


 Thanks !!

5-Regular Member
August 19, 2021

Hi @pshashipreetham ,

 As far as i know ThingWorx DateFunctions uses Joda DateTimeFormatter.   

joda date time format 

 

Kindly check once.

Bhawna