Coder Social home page Coder Social logo

leesiongchan / moment-msdate Goto Github PK

View Code? Open in Web Editor NEW

This project forked from markitondemand/moment-msdate

0.0 3.0 0.0 55 KB

Moment.js plugin for parsing OLE Automation dates

Home Page: http://markitondemand.github.io/moment-msdate/

License: Apache License 2.0

JavaScript 100.00%

moment-msdate's Introduction

moment-msdate

A Moment.js plugin for parsing OLE Automation dates.

Visit http://markitondemand.github.io/moment-msdate/ for more information and examples.

About OLE Automation Dates

An OLE Automation date, or "MSDate" as we call it, is implemented as a floating-point number whose integral component is the number of days before or after midnight, 30 December 1899, and whose fractional component represents the time on that day divided by 24. For example, midnight, 31 December 1899 is represented by 1.0; 6 A.M., 1 January 1900 is represented by 2.25; midnight, 29 December 1899 is represented by -1.0; and 6 A.M., 29 December 1899 is represented by -1.25.

Read more about OLE Automation on MSDN (including DateTime.ToOADate and DateTime.FromOADate).

Usage

toOADate()

Convert a moment to an OA date:

moment().toOADate();

This API returns a floating-point number (the OA date), so once the conversion has been made, you no longer have a moment object.

fromOADate()

Convert an OA date to a moment (or to a JavaScript date):

moment.fromOADate(41493) returns Wed Aug 07 2013 00:00:00 GMT-0600 (MDT)

For exact date and time (time is the value right of the decimal):

moment.fromOADate(41493.706892280097000) returns Wed Aug 07 2013 16:57:55 GMT-0600 (MDT)

For Moment formatting:

//convert OA date into Moment (JavaScript date)
var momentDate = moment.fromOADate(41493.706892280097000);

//use Moment's awesomeness
var formattedDate = momentDate.format('MMM Do YY);

//formattedDate === "Aug 7th 13"

This could easily be chained together as:

moment.fromOADate(41493.706892280097000).format('MMM Do YY); //Aug 7th 13

Note: OLE Automation dates are unspecified, meaning they’re based on the local timezone by default.

License

Copyright © 2014 Markit On Demand, Inc.

The "moment-msdate" Moment.js plugin is licensed under the Apache License, Version 2.0.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.