Summary
I'm creating my first extension for VSCode in TypeScript, and want to create a new information message to display current date/time.
What I've tried
I've tried looking for some data/time keyword in the list of vscode key bindings. I've also tried looking for a function to get system date/time on Google only to come across solutions explaining data/time syntax and how to display a specific date/time but nothing to get the CURRENT data/time. I've also looked for it in vscode API documentation.
Code part
According to my understanding the code should be in extension.ts
file in activate
section where I register the command to implement showInformationMessage
function call and send a string to it containing the date/time. So here is the code around the line where I store the current date/time:
let disposableShowTime = vscode.commands.registerCommand( "extension.showTime", () => { // Display a message box to the user let dateTime = "22 March, 2019 12:45PM"; // store current data/time instead vscode.window.showInformationMessage("Current time: " + dateTime); } );
Desired output: [Current Date/Time]
Actual output: 22 March, 2019 12:45PM
The Date object represents a date and time functionality in TypeScript. It allows us to get or set the year, month and day, hour, minute, second, and millisecond.
Every class or interface can be used as a type in TypeScript. const date = new Date();
If you use angular and Moment type
import * as moment from 'moment'; ... //Change DATE_TIME_FORMAT by the format need const DATE_TIME_FORMAT = 'YYYY-MM-DDTHH:mm'; let _now: Moment; _now = moment(new Date(), DATE_TIME_FORMAT);
To retrieve the current system Date/Time in javaScript/TypeScript you need to create a new Date
object using parameterless constructor, like this:
let dateTime = new Date()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With