cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

Date Format issue, while converting string to DateTime

pshashipreetham
17-Peridot

Date Format issue, while converting string to DateTime

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 !!

Shashi Preetham
1 ACCEPTED SOLUTION

Accepted Solutions

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

View solution in original post

5 REPLIES 5

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

Hi @bchaudhary ,

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 !!

Shashi Preetham

Hi @pshashipreetham ,

 As far as i know ThingWorx DateFunctions uses Joda DateTimeFormatter.   

joda date time format 

 

Kindly check once.

Bhawna

 

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

Hi @bchaudhary ,

I have timestamp in the grid column, so I wanted it in the "HH:mm:ss dd/MM/yyyy", how can I do with Localization Token, I have tried but it Didn't work !!

Can you help me out over here ?

Thanks !!

Shashi Preetham
Top Tags