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 Dynamic Upload multiple files with extra detail of model in asp.net core
How To Dynamic Upload multiple files with extra detail of model in asp.net core 1). firstly create Model File namespace MyModel { pub...
Popular Posts
-
How To Get IP Address And MAC Address Using c# , Aps.net MVC public ActionResult Index() { var IP = GetUser_IP(); ...
-
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 Add AngularJs In Visual Studio or Add Nuget Package in VisualStudio Before Add Controller And Nuget Package of A...
-
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 Add Entity Data Model In Project Of MVC Before Add Entity Mode First You Need to Know How To Add New Project In Asp.net MVC fo...