I create content for .NET MVC. My work appears in the .NET MVC documentation site. I'm primarily responsible for the section that will help you learn C#.also Some Of Computer Technologie and Other Front-End Language Like Html Css And Java Scripts In Easier way eCommerce Web,Web Portal,Mobile App Website,One Page Website / Single Page
Asp.net And HTML Css And Web Development: How to convert Dot net sql date / Date string to L...
Asp.net And HTML Css And Web Development: How to convert Dot net sql date / Date string to L...: How to convert Dot net sql date / Date string to Local UTC of moment in angular 6 1). For Use In HTML Create Pipe : In Ang...
How to convert Dot net sql date / Date string to Local UTC of moment in angular 6
How to convert Dot net sql date / Date string to Local UTC of moment in angular 6
1). For Use In HTML Create Pipe :
In Angular 6 first we Have create a pipe With Help of Command
"ng g p convertSqltoUTC "
and Now You Need to Copy paste follow Code into your pipe
import { Pipe, PipeTransform } from '@angular/core';
import * as moment from 'moment';
@Pipe({
name: 'convertUTCSqlDate'
})
export class ConvertUTCSqlDatePipe implements PipeTransform { transform(date: any, format = 'DD/MM/YYYY HH:mm:ss') {
if (date) {
let localText;
if (date instanceof moment) {
localText = moment(moment.utc(date._i, format).toDate()).format(format);
} else {
localText = moment(moment.utc(date, format).toDate()).format(format);
}
return localText; } else {
return '';
}
}}
import * as moment from 'moment';
@Pipe({
name: 'convertUTCSqlDate'
})
export class ConvertUTCSqlDatePipe implements PipeTransform { transform(date: any, format = 'DD/MM/YYYY HH:mm:ss') {
if (date) {
let localText;
if (date instanceof moment) {
localText = moment(moment.utc(date._i, format).toDate()).format(format);
} else {
localText = moment(moment.utc(date, format).toDate()).format(format);
}
return localText; } else {
return '';
}
}}
Now you can User This pipe in your html to convert Date string to Utc in any format
<h5>{{element.CreateDatre | convertUTCSqlDate }} </h5>
_________________________________________________________________
2). For Componet.ts File Use Service Like:
for Create a Service Run Below Command
"ng g s ConvertUTCSqlDateService "
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root',
})
export class ConvertUTCSqlDateService {
ConvertUTCSqlDate(date: any, format = 'DD/MM/YYYY HH:mm:ss') {
if (date) {
let localText;
if (date instanceof moment) {
localText = moment(moment.utc(date._i, format).toDate()).format(format);
} else {
localText = moment(moment.utc(date, format).toDate()).format(format);
}
return localText; } else {
return '';
}
}
}
Now You Need To Inject Service and call method return local Utc Date
Subscribe to:
Posts (Atom)
Featured Post
how to find n number of nodes have child or cildren
how to find n number of nodes have child or cildren for that we use recursive function const data = { 'id' : '0' ,...

Popular Posts
-
how to post formdata or http.context.form data from angular 6 to asp.net mvc web api or api using Token based authentication with header ...
-
How To Design Certificate using Html CSS And Format for print landscape and portrait Mode page Design OUTPUT:- HTML AND CSS...
-
How To Get IP Address And MAC Address Using c# , Aps.net MVC public ActionResult Index() { var IP = GetUser_IP(); ...
-
How to Create xml file and download it or convert into base64 string 1).First Install Following packages from Node m...
-
Using Angular in ASP.NET MVC 5 with Angular CLI and Visual Studio 2017 Angular is one of most in-demand web front-end fram...
-
How to auto load data on mat-select scroll (mat-select infinite scroll) step1 :Install plugins npm i ng-mat-select-infinite-scroll refere...