Home > Software design >  Separating Date and Time
Separating Date and Time

Time:02-08

I have a table displaying in my angular component and one of the columns is the date but it mashes the date and time together. I've tried separating them but I haven't had much luck doing so. the loop for placing each row of the csv data into my array obj is as follows:

let lines = csv.split("\n")
let headers = lines[0].split(/,/)
for(let i = 1; i < lines.length; i  ) {
        let currLine = lines[i].split(",")

then i try to manipulate the date element:

I've tried to separate the the date column into different array pieces for each char then put them back together but when I try to separate the date string it throws an error.

let jObj = currLine[1].split("")

ERROR Error: Uncaught (in promise): TypeError: Cannot read properties of undefined (reading 'split')

I've also tried to do the .replace("T", " ") so that way I could just split it by a " " but again it throws an error.

let jObj = currLine[1].replace("T", " ")

ERROR Error: Uncaught (in promise): TypeError: Cannot read properties of undefined (reading 'replace')

not sure if its a problem trying to separate an array element or my typescript coding. Can someone give me some suggestions please?

Screenshot of table

CodePudding user response:

As an alternative, rather than worry about splitting the date and time whilst reading it in from the file, you could always use the Angulare date pipe to format the datetime however you like.

https://angular.io/api/common/DatePipe

  •  Tags:  
  • Related