3

How to show Friendly Date in SharePoint using Javascript or using Server side code

 

JAVASCRIPT

You can use following javascript code in order to show Date field value in Friendly format


var yourDate = new Date();

var friendlyDate = SP.DateTimeUtil.SPRelativeDateTime.getRelativeDateTimeString(yourDate , true, SP.DateTimeUtil.SPCalendarType.none, false)

console.log(friendlyDate);

 

Note that you need to add reference of “SP.dateTimeUtil.js” js in your page

<script type="text/javascript" src="/_layouts/15/SP.dateTimeUtil.js></script>

Following is the description about method argument:
1. Your date (Date ISO8601)
2. Specify whether want to include tiem or not(IncludeTime)
3. Calendar type (CalendarType)
4. Specify whether want to adjust time with server(AdjustToServersNowTime)
————————————————————————–
SERVER SIDE


DateTime date = DateTime.Now;
string friendlyDate = SPRelativeDateTime.GetRelativeDateString(web, date.ToUniversalTime(), date); 

I Hope it will same someone’s time.
 

Advertisements
0

Event Receivers fires for all lists and libraries

Issue Case – Event Receiver behaving unexpectedly

I want to add my event receiver in all the document library in whole site collection.So i added event receiver like
<?xml version=”1.0″ encoding=”utf-8″?>
<Elements xmlns=”http://schemas.microsoft.com/sharepoint/“>
<Receivers ListTemplateId=”101”>
<Receiver>
<Name>DenyToUpdateMDItemAdded</Name>
<Type>ItemAdded</Type>
<Assembly>[Assembly]</Assembly>
<Class>[Class Path]</Class>
<SequenceNumber>10000</SequenceNumber>
</Receiver>
</Receivers>
</Elements>

The scope of the feature is “Site” as i want to add event receiver in all the sub site also.

When i activated my event receiver feature, event receiver fires for all the list and libraries.

Issue Case – Event Receiver behaving unexpectedly

 

SOLUTION

By Just changing  the scope of the feature “Site” to “web” my problem was resolved

Don’t know whether its sharepoint bug or not:). Hope it will save some time