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

Date Format issue, while converting string to DateTime

psp316r
16-Pearl

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

1 ACCEPTED SOLUTION

Accepted Solutions
bchaudhary
14-Alexandrite
(To:psp316r)

Hello @psp316r ,

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
bchaudhary
14-Alexandrite
(To:psp316r)

Hi @psp316r ,

 

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

bchaudhary
14-Alexandrite
(To:psp316r)

Hi @psp316r ,

 As far as i know ThingWorx DateFunctions uses Joda DateTimeFormatter.   

joda date time format 

 

Kindly check once.

Bhawna

 

bchaudhary
14-Alexandrite
(To:psp316r)

Hello @psp316r ,

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

Announcements